Increment year by one

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
pdntsap
Premium Member
Premium Member
Posts: 107
Joined: Mon Jul 04, 2011 5:38 pm

Increment year by one

Post by pdntsap »

Hello,

We have a field stored as Date type in the following format: 10/18/11. I am looking for options to increase the year by one (to 10/18/12). Any suggestions are highly appreciated.

Also, is my following understanding of DaysSinceFromDate() function right.

Code: Select all

DaysSinceFromDate(10/17/12, 10/18/12)
will return one. Is that right?

Thanks.
MarkB
Premium Member
Premium Member
Posts: 95
Joined: Fri Oct 27, 2006 9:13 am

Post by MarkB »

There are multiple ways to add a year - here is one way (in the example I am just using CurrentDate() ):

Code: Select all

StringToDate( YearFromDate(CurrentDate())+1:'-':MonthFromDate(CurrentDate()):'-':MonthDayFromDate(CurrentDate()))
As to your example, no - it will return a -1. DaysSinceFromDate uses (source date,given date) and returns the days from the given date to the source date, and the 17th was one day earlier (-1) from the 18th. In order to get 1, you would have to reverse the dates.
pdntsap
Premium Member
Premium Member
Posts: 107
Joined: Mon Jul 04, 2011 5:38 pm

Post by pdntsap »

Thanks Mark.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As noted, multiple ways... do you need to worry about the year after a leap year?
-craig

"You can never have too many knives" -- Logan Nine Fingers
pdntsap
Premium Member
Premium Member
Posts: 107
Joined: Mon Jul 04, 2011 5:38 pm

Post by pdntsap »

I do not need to worry about the year after leap year. I compare two dates (to and fro) and if the fro date is less than the to date, then increase the year by one on the fro date. Thanks.
MarkB
Premium Member
Premium Member
Posts: 95
Joined: Fri Oct 27, 2006 9:13 am

Post by MarkB »

pdntsap wrote:I do not need to worry about the year after leap year. I compare two dates (to and fro) and if the fro date is less than the to date, then increase the year by one on the fro date. Thanks.
But as Craig noted, if you are doing as suggested, you really SHOULD address the leap year issue. If your from date is 02-29-2012 and you increase the year by one, you'll get 02-29-2013, which doesn't exist. Not a good thing. :cry:

You should check if the from date is 02-29; if it is, you'll need to change it to 02-28 before adding a year.
pdntsap
Premium Member
Premium Member
Posts: 107
Joined: Mon Jul 04, 2011 5:38 pm

Post by pdntsap »

That is true. I guess I need to implement the leap year logic as well. Thanks.
Post Reply