加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用Bash计算AIX中两个日期之间的天数

发布时间:2020-12-15 20:54:45 所属栏目:安全 来源:网络整理
导读:我试图找出两个日期的日期.下面是我在UNIX上完美运行的代码. date1=$(date "+%m/%d/%y")temp1=4/8/24echo $((($(date -u -d $temp1 +%s) - $(date -u -d $date1 +%s)) / 86400)) 当我在AIX框上执行上面的脚本时,我收到以下错误: date: Not a recognized fla
我试图找出两个日期的日期.下面是我在UNIX上完美运行的代码.

date1=$(date "+%m/%d/%y")
temp1=4/8/24
echo $((($(date -u -d $temp1 +%s) - $(date -u -d $date1 +%s)) / 86400))

当我在AIX框上执行上面的脚本时,我收到以下错误:

date: Not a recognized flag: d

Usage: date [-u] [+”Field Descriptors”]

date: Not a recognized flag: d

Usage: date [-u] [+”Field Descriptors”]

( – ) / 86400: syntax error: operand expected (error token is “) / 86400”)`

这是一个PROD环境,我没有管理员权限来安装任何包.

解决方法

这假定一个月是一年的1/12,并且您使用正确的4位数
年份:

#!/usr/bin/awk -f
function mktm(datespec) {
  split(datespec,q,"/")
  return 
  (q[3] - 1970) * 60 * 60 * 24 * 365.25 + 
  (q[1] -    1) * 60 * 60 * 24 * 365.25 / 12 + 
  (q[2] -    1) * 60 * 60 * 24
}
function ceil(x) {
  y = int(x); return y < x ? y + 1 : y
}
BEGIN {
  srand()
  print ceil((mktm(ARGV[1]) - srand()) / (60 * 60 * 24))
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读