Calculate Months Since from Date

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
velagapudi_k
Premium Member
Premium Member
Posts: 142
Joined: Mon Jun 27, 2005 5:31 pm
Location: Atlanta GA

Calculate Months Since from Date

Post by velagapudi_k »

Folks, I am trying to calculate number of months since from a given date.
I know Datastage has DaysSinceFromDate and I can do either
days/30 or (days/365)*12. The second one is much accurate. Please let me know if there is a better way. Appreciate your help.
Venkat Velagapudi
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Compute the YYYY and the MM from a date and compute X as ((YYYY*12)+MM). Do the same for the other date and subtract the larger from the smaller. This returns 0 for (2012-08-31::2012-08-31) and 1 for (2012-08-31::2012-09-01) and would be the number of calendar months between the two dates and might be a better value than rouding the number of days to months -- but it depends upon what the end-user/customer really wants.
Post Reply