subtract 1 hour from date in unix shell script

前端 未结 8 1100
鱼传尺愫
鱼传尺愫 2020-12-16 08:42

I have the following in a shell script. How can I subtract one hour while retaining the formatting?

DATE=`date \"+%m/%d/%Y -%H:%M:%S\"`
8条回答
  •  旧巷少年郎
    2020-12-16 09:34

    Here another way to subtract 1 hour.

    yesterdayDate=`date -d '2018-11-24 00:09 -1 hour' +'%Y-%m-%d %H:%M'` 
    echo $yesterdayDate
    
    Output:
    2018-11-23 23:09
    

    I hope that It can help someone. Best Regards!

提交回复
热议问题