2 Replies Latest reply on Dec 31, 2009 7:09 PM by JeffryHouser

# Calculating the time in years between two date var's.

Hello to who is reading this post!

I have tried to calculate the time in years between two time var's as fallows..

...((Now.getTime()-SomeDate.getTime())/(365*milliSecondsPerDay));

.. the logic made sense, but the tests showed something else.

Do you have any suggestions how to solve this question.

Herendi Kristóf Pál

• ###### 1. Re: Calculating the time in years between two date var's.

Your logic seems good to me.The below code gives me 1 year, as expected.

var milliSecondsPerDay:uint = 1000 * 60 * 60 * 24;
var SomeDate:Date = new Date(2008,11,31,20,45,0,0);
var Now:Date = new Date();
trace ((Now.getTime() - SomeDate.getTime())/(365*milliSecondsPerDay));

Chris

• ###### 2. Re: Calculating the time in years between two date var's.

There should be a method in the open source DateUtils class that can be used for calculating the length of time between two date variables:

http://flexoop.com/category/code/flexdateutils/