Skip to content

Instantly share code, notes, and snippets.

@josh-padnick
Created March 25, 2014 18:03
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 josh-padnick/9767567 to your computer and use it in GitHub Desktop.
Save josh-padnick/9767567 to your computer and use it in GitHub Desktop.
Compute Estimated Gestational Age from Due Date (Javascript)
// Usage: computeEGA(2014, 4, 14);
// Computes the Estimated Gestational Age of a patient based on today's date and her Expected Due Date (EDD)
// Sample data
var iDueDateYear = 2014;
var iDueDateMonth = 4;
var iDueDateDay = 14;
function computeEGA( iDueDateYear, iDueDateMonth, iDueDateDay ) {
var dToday = new Date();
var dDueDate = new Date( iDueDateYear, iDueDateMonth-1, iDueDateDay );
var iDaysUntilDueDate = (dDueDate - dToday) / (1000 * 60 * 60 * 24 );
var iTotalDaysInPregnancy = 40*7;
var iGestationalAgeInDays = iTotalDaysInPregnancy - iDaysUntilDueDate;
var fGestationalAgeInWeeks = iGestationalAgeInDays / 7;
var iEGAWeeks = Math.floor( fGestationalAgeInWeeks );
var iEGADays = ((fGestationalAgeInWeeks % 1)*7).toFixed(0)
console.log( iEGAWeeks + " weeks" );
console.log( iEGADays + " days" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment