首页 > 解决方案 > 如何对 MM/DD/YYYY 格式的日期进行数学运算?

问题描述

我有一个包含MM/DD/YYY格式日期列表的文件。这些中的每一个都存储在$date_variable一个while循环中。我也有:

current_date="$( date +%x )"

我需要将文件中的日期与$current_date.

我怎么能说“如果当前日期 = $date_variable + 至少 7 天?或者”如果自 $date_variable 以来至少已经过去了 7 天,那么就这样做”。

我曾尝试使用“if”比较运算符,但由于$date_variable.

此外,我发现很难更改 的格式,$date_variable因为它们是从带有curl和的网页中获取的grep

编辑:

我的脚本如下所示:

# Store current date in the MM/DD/YYYY format
current_date="$( date +%x )"

# Iterate each line from hotfix_final and read the variables hf_link and release_date
while read -r hf_link release_date; do

  # Install hotfixes on POC machines
  if [ "$current_date" > "$release_date" ]; then
    wget "$hf_link"
  fi

done </home/abc/hotfix_final # Set the file as input for the whole while loop

hotfix_final:

https://download.abc.com/hotfix 06/24/2019
https://download.abc.com/hotfix2 06/26/2019

我想说:

if "$current_date" = "$release_date" + at least 7 days; then ...; fi

标签: bashshelldate

解决方案


推荐阅读