Skip to content

Instantly share code, notes, and snippets.

@spencerdeinum
Last active December 18, 2015 12:39
Show Gist options
  • Save spencerdeinum/5783967 to your computer and use it in GitHub Desktop.
Save spencerdeinum/5783967 to your computer and use it in GitHub Desktop.
Moment js is awesome
$(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