Find the time in years between two dates.
Last active
January 1, 2016 13:39
-
-
Save joyrexus/8152481 to your computer and use it in GitHub Desktop.
Time in years between two dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert = require 'assert' | |
years = require 'years' | |
from = new Date("Jan 20, 2009") | |
to = new Date("Aug 1, 2011") | |
assert.ok 2 < years(from, to) < 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find the time in years between two dates | |
module.exports = (begin, end) -> | |
end ?= new Date() | |
time = end - begin | |
secs = time / 1000 | |
mins = secs / 60 | |
hours = mins / 60 | |
days = hours / 24 | |
years = days / 365 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment