user3531971
user3531971

Reputation: 33

How can i get first day and last day of previous month in shell script

In my script i need to get the first day and last day of previous month. the format should be like for April month:

1-April-2014 30-April-2014

I am very new to unix please help me

Thanks in advance

Upvotes: 1

Views: 2214

Answers (1)

Kent
Kent

Reputation: 195049

I assume you have gnu date, then check the following:

first day of last month:

kent$  date -d"1 $(date -d'last month' +%b)" +%F   
2014-04-01

last day of last month:

kent$  date -d"-1 day 1 $(date +%b)" +%F        
2014-04-30

Upvotes: 3

Related Questions