How to Compare Two Dates in AS3

var daysApart = getDaysBetweenDates(new Date(), new Date(2011, 1, 11))
trace(daysApart);

function getDaysBetweenDates(date1:Date,date2:Date):int
{
	var oneDay:Number = 1000 * 60 * 60 * 24;
	var date1Milliseconds:Number = date1.getTime();
	var date2Milliseconds:Number = date2.getTime();		    
	var differenceMilliseconds:Number = Math.abs(date1Milliseconds - date2Milliseconds);
	return Math.round(differenceMilliseconds/oneDay);
}

3 Responses to “How to Compare Two Dates in AS3”

  1. This was super useful!!! thanks :D

  2. Thanks!!! :)

  3. Great!

    Thank you so much!

Leave a Reply