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
how to retrieve months between two dates of different years
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 92
- Joined: Wed Mar 05, 2008 4:09 am
- Location: chennai
- Contact:
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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
-
- Participant
- Posts: 92
- Joined: Wed Mar 05, 2008 4:09 am
- Location: chennai
- Contact:
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Premium Member
- Posts: 45
- Joined: Fri Nov 07, 2008 12:22 pm
Re: how to retrieve months between two dates of different ye
There is no direct way to get the number of months. But here's an indirect way: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
DaysSinceFromDate(CurrentDate(),"2008/02/03") / 30
It worked for me.. See if it helps.
Thanks,
Hiral
Thanks,
Hiral Chauhan
Hiral Chauhan
Re: how to retrieve months between two dates of different ye
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.
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: