date calculation

I have been struggling with the following calculation for some hours.

Inputfield: startdate [date]
Inputfield: enddate [date]
calculationfield: calc [number]

pseudocode: calc = (enddate - 1 day) - startdate // result in number of years starting with 0

not working code:

var sd=startdate;
var ed=enddate;
var ed1=enddate.setDate(enddate.getDate()+1);
var diffms=ed1-sd ;
var diffyr=(diffms/(10006060*24)/365;
var diffyrfl=Math.floor(diffyr);
return diffyrfl;

Any help will be appreciated.

Regards,

Ron

Hi Ron

When using date calcs I usually set them into a calculated number field that returns ‘yyyymmdd’ using

return (qt_date.getFullYear()* 10000) + ((qt_date.getMonth() + 1)* 100) + qt_date.getDate()

22/12/2004 = 20041222 & 20/06/2005 = 20050605

Maybe you could use a subset of this for your calc

Regards

Graham Greensall
Worxinfo Ltd

Interesting approach, I’ll give it a try.
Thanks.

Regards,

Ron