Page 1 of 1

PHP Time Difference Script - How?

Posted: Sat Jan 06, 2007 11:22 pm
by thenext88
So I really don't know how to make a "time difference" script, and I sort of need one. I'm also still new with php, so if I did some stupid things like put variables where they shouldn't be, please let me know as well.

I need a script that can take a date given in m d Y g:i format, and find out the difference between the current, and that date.

I tried to make a test script, which failed, because I keep getting 0 as my answer.

Any suggestions and help would be greatly appreciated.

Code: Select all

<?php 

$time = date('m d Y g:i');
echo "$time";

echo "<br><br>";

$tomorrow = mktime(date("g"),date("i"),0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("m d Y g:i", $tomorrow);

echo "<br><br>";

$start = strtotime ($time);

$end = strtotime ($tomorrow);

$diff = $end - $start;

echo "$diff";

?>
Edit: got rid of gets

Posted: Sat Jan 06, 2007 11:32 pm
by feyd
Are you accepting user input into this script? $_GET is looking for user input (via the URL.) I'm going to guess that's not your intention; so remove the $_GET business. You only need $time and $tomorrow.

$tomorrow doesn't need to be passed through strtotime(). And $time could easily parse wrong, so just use time().