For a project at work I had to display how many days the visitor of the app had left to still join in on the fun. We had a fixed date (the launch of the project) and a variable date (the date of the day that the project visitor actually visited/used the app). So I was in the need of a script that counts the days between two dates. I know, not that hard, but good to have around nonetheless. Quick snippets for the win!

Anyway, the snippet is pretty clear:

- one variable that represents a day (milliseconds times seconds times minutes times hours)
- two dates turned to milliseconds by “getTime()”
- the difference between those milliseconds

The result of that gets divided by the day in milliseconds and voila: a between days counter!

private function getDaysBetweenDates(date1:Date,date2:Date):int {
	var durationDay:Number = 1000 * 60 * 60 * 24
	var date1InMilli:Number = date1.getTime();
	var date2InMilli:Number = date2.getTime();		    
	var differenceInMilli:Number = Math.abs(date1InMilli - date2InMilli)		    
	return Math.round(differenceInMilli_ms/durationDay);
}