Using `date` command to get previous, current and next month

前端 未结 4 971
感情败类
感情败类 2020-12-02 09:03

I am using below to get previous, current and the next month under Ubuntu 11.04:

LAST_MONTH=`date +\'%m\' -d \'last month\'`
NEXT_MONTH=`date +\         


        
4条回答
  •  Happy的楠姐
    2020-12-02 09:53

    the main problem occur when you don't have date --date option available and you don't have permission to install it, then try below -

    Previous month
    #cal -3|awk 'NR==1{print toupper(substr($1,1,3))"-"$2}'
    DEC-2016 
    Current month
    #cal -3|awk 'NR==1{print toupper(substr($3,1,3))"-"$4}'
    JAN-2017
    Next month
    #cal -3|awk 'NR==1{print toupper(substr($5,1,3))"-"$6}'
    FEB-2017
    

提交回复
热议问题