1. Home
  2. Computing & Technology
  3. PHP / MySQL

Pregnancy Due Date Calculator

By Angela Bradley, About.com

1 of 2

Calculating a date

<?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.)

1 of 2

Index: Pregnancy Due Date Calculator

  1. Calculating a date
  2. Collecting The Date

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. PHP Pregnancy Calculator - PHP Due Date Calculator

©2008 About.com, a part of The New York Times Company.

All rights reserved.