user32770
user32770

Reputation: 61

display date with last month information

I know the command many display current month and year .

#date +%b%Y

Jun2015

If I want to show the last month and year ( as current month is Jun2015, I would like display May2015 , if current is Jan2016 , then display Dec2015 ) , would advise what can I do ? thanks

Upvotes: 0

Views: 61

Answers (2)

umläute
umläute

Reputation: 31284

you can specify a relative date you want to be printed:

$ date --date 'last month' +'%b%Y'
May2015

Upvotes: 1

Yahya Yahyaoui
Yahya Yahyaoui

Reputation: 2953

date --date='-1 month' +'%b%Y'

example:

date --date='-7 month' +'%b%Y'

Gives: "Nov2014"

Upvotes: 1

Related Questions