Last active
December 18, 2015 12:39
-
-
Save spencerdeinum/5783967 to your computer and use it in GitHub Desktop.
Moment js is awesome
This file contains hidden or 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
$(function() { | |
$('#patient_age').on('change', function() { | |
var birth_year = moment().subtract('years', $(this).val()); | |
birth_year.startOf('year'); | |
$('#date_of_birth').val(birth_year.format('YYYY-MM-DD')); | |
}); | |
$('#date_of_birth').on('change', function() { | |
var date_of_birth = moment($(this).val()); | |
var years = moment().diff(date_of_birth, 'years'); | |
$('#patient_age').val(years); | |
}).change(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment