Page 1 of 1

date difference

Posted: Thu Jul 29, 2010 10:02 am
by developeretl
Iam having the date difference issue
I have a col1 with some codes like A,B,C and another col with dates ,date column in this format 20100724
So my condition is that if Col1 is 'A' then populate a column with the one year reduced that is difference 1. Can you please help me with this issue

Example: if col1='A' then ( 20100724) in the result i should get 20090724

Re: date difference

Posted: Thu Jul 29, 2010 10:20 am
by kris007
You can do something like

Code: Select all

If Col1 = 'A' Then Date[1,4] - 1: Date[5,8]
That should work. The only challenge for you is to put in some additional logic when the Date you have is a leap Year and it is Feb 29. Then the last year date would be Feb28 of that year.

Hope that helps.

Re: date difference

Posted: Thu Jul 29, 2010 11:07 am
by developeretl
kris007 wrote:You can do something like

Code: Select all

If Col1 = 'A' Then Date[1,4] - 1: Date[5,8]
That should work. The only challenge for you is to put in some additional logic when the Date you have is a leap Year and it is Feb 29. Then the last year date would be Feb28 of that year.

Hope that helps.
Hi Kris,
Iam doing the difference for year only.

Re: date difference

Posted: Thu Jul 29, 2010 11:08 am
by developeretl
kris007 wrote:You can do something like

Code: Select all

If Col1 = 'A' Then Date[1,4] - 1: Date[5,8]
That should work. The only challenge for you is to put in some additional logic when the Date you have is a leap Year and it is Feb 29. Then the last year date would be Feb28 of that year.

Hope that helps.
Hi Kris,
Iam doing the difference for year only.

Re: date difference

Posted: Thu Jul 29, 2010 11:30 am
by kris007
Yes. But what if your input date is 20080229. What should be your output? 20070229 (which is invalid) or 20080228.

Posted: Thu Jul 29, 2010 11:44 am
by datisaq
But i think it needs date to string conversions before doing that...
Or Is it implicit??