Posted 27 July 2006 - 02:19 AM
Ok, i'm tryin to calculate the difference between two times. One is a small distance into the future and is in the format(0000-00-00 00:00:00). Lets call this x.
The other is the current time, lets call this y.
I want to calculate how long it will be until y = x.
How should i go about doing this?
If you need more info just ask.
Posted 27 July 2006 - 02:27 AM
or here is an example straight out of the manual
<?php $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now: '. date('Y-m-d') ."\n"; echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n"; ?>
Posted 27 July 2006 - 03:26 AM
Both are in the same format, i just don't know the syntax of single quotes and periods very well and am not sure how to use it in this situation.
e.g echo 'today '. $time2 .' - '. date('Y-m-d H:i:s') ."\n";
What should i change this to to make it actually calcualte the answer?
Posted 27 July 2006 - 03:31 AM
Posted 27 July 2006 - 03:45 AM
$time5 = "2006-07-27 05:05:51";
$time4= date('Y-m-d H:i:s');
$time = $time5 - $time4;
The output i'm getting is: 0
Just a zero by itself!
Posted 27 July 2006 - 04:30 AM
how can (2006-07-27 05:05:51) - (2006-7-56 11:30:50) be solved? Thats your problem.
Posted 27 July 2006 - 04:54 AM
strtotime($time5) - strtotime($time4)
This will give you the number of seconds difference between the two times.
Then it's up to you to calculate the number of mins, hours, days, or whatever you are looking for.
Posted 27 July 2006 - 05:19 AM
Posted 27 July 2006 - 05:26 AM
Something along these lines should work
$mins = $totalSec / 60; $leftoverSec = $totalSec - ($mins * 60); echo "$mins m $leftoverSec s";
Posted 27 July 2006 - 05:40 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users