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

Pregnancy Due Date Calculator

By , About.com Guide

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.)
Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

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

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

All rights reserved.