Page 1 of 1

how to retrieve months between two dates of different years

Posted: Wed Mar 25, 2009 11:12 pm
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

Posted: Wed Mar 25, 2009 11:37 pm
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.

Posted: Thu Mar 26, 2009 12:33 am
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

Posted: Thu Mar 26, 2009 12:43 am
by pradeep_nov18
Hi Kryt0n

I just want the count the no of month between two dates,how achieve these.

Posted: Thu Mar 26, 2009 1:06 am
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.

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

Posted: Fri Mar 27, 2009 4:39 pm
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

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

Posted: Sat Mar 28, 2009 10:50 pm
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.

Posted: Sun Mar 29, 2009 12:52 am
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.