Shell脚本获取两个日期之间的差异 [英] Shell script to get difference between two dates

查看:57
本文介绍了Shell脚本获取两个日期之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果日期为2010-06-01,日期为2010-05-15

If there are dates as 2010-06-01 and another as 2010-05-15

使用shell脚本或date命令如何获取两个日期之间的天数

Using shell script or date command how to get the number of days between the two dates

谢谢..

推荐答案

仅使用日期和Shell算术:

Using only date and shell arithmetics:

echo $((($(date -d "2010-06-01" "+%s") - $(date -d "2010-05-15" "+%s")) / 86400))

这篇关于Shell脚本获取两个日期之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆