linux date获取月初和月末

2024-12-02

linux date获取月初和月末

1、上月初
date -d "1 month ago" +%Y%m01
date -d last-month +%Y%m01

2、上月末
date -d "$(date +'%Y-%m-01') -1day"
date -d "$(date +%Y%m01) -1day" +%Y%m%d

3、实例
cat << EOF > last-month.sh
lm_first=$(date -d last-month +%Y%m01)
lm_end=$(date -d "$(date +%Y%m01) -1day" +%Y%m%d)
echo $lm_first $lm_end
sh x1月初充值数据累计.sh $lm_first $lm_end
sh y2月初消耗数据累计.sh $lm_first $lm_end
sh z3月初剩余条数累计.sh $lm_first $lm_end
EOF

分类:Linux | 标签: |

相关日志

评论被关闭!