ken bohnenkamp
14th May 2008, 05:44
Does anyone know how to easily determine the number of months between 2 dates
ie.
03/03/2007 thru 01/15/2009 = 23 months
george7a
14th May 2008, 08:51
Hi,
Using the date.to.num (http://www.baanboard.com/programmers_manual_baanerp_help_functions_date_time_zones_date_to_num) function you can get the number of days since 01.01.01. Using that you can get the number of months. Here is the equation I came up with:
months = round((date.to.num( 2009, 01, 15 ) - date.to.num( 2007, 03, 03 )) * 0.0328 ,0,2)
I hope it helps,
- George
vahdani
14th May 2008, 12:16
Hi Ken,
assumin that you already use Baan dates which are by definition days since 01.01.01 then here is my solution:
months = date.diff.in.months(start.date, end.date)
...
...
function long date.diff.in.months( domain tcdate i.date.f,
domain tcdate i.date.t)
{
long y1, m1, d1
long y2, m2, d2
long ret, months
months = 0
ret = num.to.date(i.date.f, y1, m1, d1)
if ret = 0 then
ret = num.to.date(i.date.t, y2, m2, d2)
if ret = 0 then
months = (y2 - y1)* 12 + (m2 - m1)
|Following as per your requirement!!:
if d2 > d1 then
months = months + 1
endif
endif
endif
return( months)
}