Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active January 1, 2016 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/8152481 to your computer and use it in GitHub Desktop.
Save joyrexus/8152481 to your computer and use it in GitHub Desktop.
Time in years between two dates

Find the time in years between two dates.

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
# 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