Re: Date - how to get (year -1) (119 Views)
Reply
Regular Advisor
Fenglin
Posts: 152
Registered: ‎05-13-2008
Message 1 of 8 (119 Views)

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
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,853
Registered: ‎03-06-2006
Message 2 of 8 (119 Views)

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.
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,853
Registered: ‎03-06-2006
Message 3 of 8 (119 Views)

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 ))
Please use plain text.
Honored Contributor
Suraj K Sankari
Posts: 1,659
Registered: ‎09-09-2008
Message 4 of 8 (119 Views)

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
Please use plain text.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,185
Registered: ‎10-13-1997
Message 5 of 8 (119 Views)

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
Please use plain text.
Trusted Contributor
Tor-Arne Nostdal
Posts: 268
Registered: ‎08-17-1998
Message 6 of 8 (119 Views)

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...
Please use plain text.
Regular Advisor
Fenglin
Posts: 152
Registered: ‎05-13-2008
Message 7 of 8 (119 Views)

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

Thanks to all.

Regards
Feng Lin
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,853
Registered: ‎03-06-2006
Message 8 of 8 (119 Views)

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
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation