Re: Date - how to get (year -1) (305 Views)
Regular Advisor
Posts: 152
Registered: ‎05-13-2008
Message 1 of 8 (305 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
Acclaimed Contributor
Posts: 25,751
Registered: ‎03-06-2006
Message 2 of 8 (305 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.
Acclaimed Contributor
Posts: 25,751
Registered: ‎03-06-2006
Message 3 of 8 (305 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 ))
Honored Contributor
Posts: 1,659
Registered: ‎09-09-2008
Message 4 of 8 (305 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
Honored Contributor
Posts: 6,191
Registered: ‎10-13-1997
Message 5 of 8 (305 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
Trusted Contributor
Posts: 268
Registered: ‎08-17-1998
Message 6 of 8 (305 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...
Regular Advisor
Posts: 152
Registered: ‎05-13-2008
Message 7 of 8 (305 Views)

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

Thanks to all.

Regards
Feng Lin
Acclaimed Contributor
Posts: 25,751
Registered: ‎03-06-2006
Message 8 of 8 (305 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
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.