how to retrieve months between two dates of different years

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
pradeep_nov18
Participant
Posts: 92
Joined: Wed Mar 05, 2008 4:09 am
Location: chennai
Contact:

how to retrieve months between two dates of different years

Post by pradeep_nov18 »

Hi Experts,

I have requirement like

For eg:
In.col1=01-01-2007
in.col2=01-03-2009

i have to take how many months are there in output between two above dates.

Please let me know how to achieve these.

Thanks in Advance
pradeep.v
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What's the answer?

The solution will depend on your business rules for handling situations where the day number is not the same in the two dates.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

Not aware of one...

but

(Year2-Year1) * 12 + (Month2-Month1)

should give the answer... and does depend on what Ray said... do you want months between 2009-02-28 and 2009-03-01 to be 0 or 1 month?

If whole months only then a check to see if Day1 > Day2 and subtracting 1 if true?

Something like that anyway
pradeep_nov18
Participant
Posts: 92
Joined: Wed Mar 05, 2008 4:09 am
Location: chennai
Contact:

Post by pradeep_nov18 »

Hi Kryt0n

I just want the count the no of month between two dates,how achieve these.
pradeep.v
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can't have that without business rules. Do you mean inclusive or exclusive counting? Ultimately these will mean one or two extra adjustments of plus or minus one in the formula, but you must get them nailed down lest we waste time giving you wrong advice.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
hiral.chauhan
Premium Member
Premium Member
Posts: 45
Joined: Fri Nov 07, 2008 12:22 pm

Re: how to retrieve months between two dates of different ye

Post by hiral.chauhan »

pradeep_nov18 wrote:Hi Experts,

I have requirement like

For eg:
In.col1=01-01-2007
in.col2=01-03-2009

i have to take how many months are there in output between two above dates.

Please let me know how to achieve these.

Thanks in Advance
There is no direct way to get the number of months. But here's an indirect way:

DaysSinceFromDate(CurrentDate(),"2008/02/03") / 30

It worked for me.. See if it helps.

Thanks,
Hiral
Thanks,
Hiral Chauhan
Pagadrai
Participant
Posts: 111
Joined: Fri Dec 31, 2004 1:16 am
Location: Chennai

Re: how to retrieve months between two dates of different ye

Post by Pagadrai »

Hi,
Just to add to what Hiral has said,
You need to use the DateSinceFromDate function for both the values i.e Date1 and Date2, get the difference between them and then divide by 30.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

This will only ever be an approximate result. To get the precise result you require a rule about how partial months are to be handled.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply