<?php
if ($go =="1")
{
$last = mktime (0,0,0,$month, $day, $year) ;
$gest = 24192000;
$due = $last + $gest;
echo "Your last cyle started on ";
echo date("M-d-Y", $last) ;
echo "<br>Your baby is due approximately ";
echo date("M-d-Y", $due) ;
echo "<p>";
}
?>
The estimated due date of a baby is calculated by adding 266 days to ovulation, or 280 days to the first day of the last menstrual cycle. For our calculation, 280 days is converted to 24192000 seconds. The code is only run if $go is set to 1, which in our case means that they have entered a date. We then take the date and put it into standard form, using the
mktime () function. Finally we
echo the date the user answered, as well as our calculated due date (their date plus 280 days.)