Actionscript 2 DateDiff function

Mostly a note to self for future reference. Not quite an implementation of the much loved datediff function, but close enough to get what I want:

// yearValue, monthValue, dayValue are assumed to be populated by the UI somewhere
startDate:Date = new Date(yearValue, monthValue, dayValue)
seconds:Number = ((new Date()).getTime() - startDate.getTime())/1000;
differenceInYears:Number = seconds / 60 / 525948.766; // google says a year is 525,948.766 minutes
The caveat here of course is that the date’s have to be after 1970, else the getTime() call won’t work.

Every language should have a date difference function and the ability to handle timespans as native types.

1 Response to “Actionscript 2 DateDiff function”


  • today = new Date (2002, 1, 27);
    tomorrow = new Date (2002, 2, 2);
    trace ((tomorrow-today)/(1000*60*60*24))

Leave a Reply