Page 1 of 1

calculating date differences

Posted: Sun Nov 24, 2002 11:39 am
by mzfp2
Hi

anybody help me calculate number of days in between two dates?

Posted: Sun Nov 24, 2002 12:47 pm
by volka
the number of seconds per day is 84600.
Convert your dates to a unix timeformat (seconds since epoch) and subtract them ;)

Posted: Sun Nov 24, 2002 10:36 pm
by oldtimer
Wish I could paste this in HTML so you could see the colors without me spending alot of time converting. However if you would like to see it go to my site here. http://www.coastgames.com/html.php?link=11

Time difference. Days past. Timestamp in format of mm/dd/yyyy


$day=substr($timestamp, 3, 2);
$month=substr($timestamp, 0, 2);
$year=substr($timestamp, 6, 4);
// Calculations
$startday = mktime ("", "", "", $month, $day, $year); // get unix time for start date
$today = time(); // todays
$difference = $today - $startday; // work out the difference
$show = floor($difference / 86400);

Time Difference. Days to come. Timestamp in format of mm/dd/yyyy

$day=substr($timestamp, 3, 2);
$month=substr($timestamp, 0, 2);
$year=substr($timestamp, 6, 4);
// Calculations
$startday = mktime ("", "", "", $month, $day, $year); // get unix time for start date
$today = time(); // todays
$difference = $startday - $today; // work out the difference
$show = floor($difference / 86400);


--------------------------------------------------------------------------------

Lets break it down. Timestamp example 10/31/2002

$month=substr($timestamp, 0, 2); (This is taking the first 2 digits for the month.)
$day=substr($timestamp, 3, 2); (This is taking the 4th and 5th digit for the day.)
$year=substr($timestamp, 6, 4); (This is takign the 7th through 10th digits for the year.)
// Calculations
$startday = mktime ("", "", "", $month, $day, $year); // get unix time for start date
$today = time(); // todays
$difference = $startday - $today; // work out the difference
$show = floor($difference / 86400);

Posted: Mon Nov 25, 2002 3:34 am
by twigletmac
If you want your PHP code to be highlighted use the [syntax=php]...[/syntax] bbcode tags:
faq.php?mode=bbcode

Mac

1070

Posted: Mon Nov 25, 2002 4:48 am
by mester
What about dates prior 1970, the Unix 'BigBang' ?

Posted: Mon Nov 25, 2002 9:44 am
by oldtimer

Code: Select all

<?php
echo "Thanks<BR>I never even noticed that Tag before.";
?>

Posted: Mon Nov 25, 2002 1:34 am Post subject:

--------------------------------------------------------------------------------

If you want your PHP code to be highlighted use the

Code: Select all

...
bbcode tags:
faq.php?mode=bbcode

Mac
?>