How can I calculate the date preceding a given date in unix?

前端 未结 4 1524
执笔经年
执笔经年 2021-01-21 16:30

I have two variables: X and Y.

The value of X will be a date given in the format mmddyy and I want to calculate the date preceding that date

4条回答
  •  醉梦人生
    2021-01-21 17:02

    Since the -d option doesn't exists on MacOS X or FreeBSD, here is the answer for them

    Retrieving a date relative to current time

    date -v -1d
    

    For your question in particular, you'll need the -j and -f flags to use a specific date

    date -v -1d -j -f %m%d%y 091509 +%Y%m%d
    

提交回复
热议问题