0

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

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by karthik_ppts
0
<?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

Edited by karthik_ppts: n/a

0

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";
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.