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

前端 未结 4 1526
执笔经年
执笔经年 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 16:57

    I like Tcl for date arithmetic, even though it's clunky for shell one-liners. Using Tcl 8.5:

    x=091509
    y=$(printf 'puts [clock format [clock add [clock scan "%s" -format "%%m%%d%%y"] -1 day] -format "%%Y%%m%%d"]' "$x" | tclsh)
    

提交回复
热议问题