Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Date - how to get (year -1)

Fenglin
Regular Advisor

Date - how to get (year -1)

Hi

how to get year-1?

YRLESS=`date +%Y-1`
echo $YRLESS
The above does not work.

Regards
Feng Lin
7 REPLIES
Dennis Handly
Acclaimed Contributor

Re: Date - how to get (year -1)

You would have to write a program. Or in perl subtract a year from now. But you would have to handle leap years, either Feb 29 doesn't exist or you would have to include an extra day, if you want the month and day to match the current year.
Dennis Handly
Acclaimed Contributor

Re: Date - how to get (year -1)

Ah, if you just want to get last year and not a date:
$ YRLESS=$(( $(date +%Y) - 1 ))
Or:
$ (( YRLESS = $(date +%Y) - 1 ))
Suraj K Sankari
Honored Contributor

Re: Date - how to get (year -1)

Hi,
You can do this way, cy=current year, py=previous year

$ cy=date +%Y
$ py=`expr $cy - 1 `
$ echo $py
2009


Suraj
H.Merijn Brand (procura
Honored Contributor

Re: Date - how to get (year -1)

$ date '+%Y-1'|bc
2009

Enjoy, Have FUN! H.Merijn [ could not resist to do it even shorter ]
Enjoy, Have FUN! H.Merijn
Tor-Arne Nostdal
Trusted Contributor

Re: Date - how to get (year -1)

let YRLESS=`date +%Y`-1
echo $YRLESS

/Tor-Arne
I'm trying to become President of the state I'm in...
Fenglin
Regular Advisor

Re: Date - how to get (year -1)

Thanks to all.

Regards
Feng Lin
Highlighted
Dennis Handly
Acclaimed Contributor

Re: Date - how to get (year -1)

>Thanks to all.

If you are happy with the answers you have gotten, please ready the following about how to assign points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33