i was reading tutorials about php date() function,
i wonder how could i write the code that show total number of days of my age till today ?
but i am stuck here,

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Example: 2010/18/12
</br>
<input type=text name="year" value="Year">/
<input type=text name="day" value="Day">/
<input type=text name="month" value="Month">
<input type="submit" name="submit" value="GO">
</form>
<?php
date_default_timezone_set ('Asia/Karachi');
if (isset ($_POST['submit'])){
$year= $_POST['year'];
$day = $_POST['day'];
$month = $_POST['month'];
echo date ("D", mktime(0,0,0,$month,$day,$year));
}

?>

this is currenty taking the input of date of birth of a user , but how can i convert it into total number of days ?
please provide me with some logic

Recommended Answers

All 4 Replies

<?php

function dateDiff($start, $end) {

$start_ts = strtotime($start);

$end_ts = strtotime($end);

$diff = $end_ts - $start_ts;

return round($diff / 86400);

}

echo dateDiff("2006-04-05", "2006-04-01");

?>

$start--------- dob
$end----------- current date

what does strtotime function do ??

convert from string to UNUX format.

<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.