Operating System - HP-UX
1752394 Members
7201 Online
108788 Solutions
New Discussion юеВ

Re: 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 7
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
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