How can I get the 1st and last date of the previou

2020-03-01 06:49发布

I have scheduled a Bash script to run on the 1st of the month but I need to create 2 variables in it with the 1st and last date of the previous month, whatever those may be.

Is it possible to do this using just Bash?

标签: bash shell
7条回答
手持菜刀,她持情操
2楼-- · 2020-03-01 07:37

You can try following date commands regardless of the day you are executing them to get first and last day of previous month

Firstday=`date -d "-1 month -$(($(date +%d)-1)) days"`
Lastday=`date -d "-$(date +%d) days"`
查看更多
登录 后发表回答