Page 1 of 1

date diff calculations didn't come right

Posted: Sat Apr 09, 2005 4:47 am
by atypk

Code: Select all

include 'config.php';
include 'opendb.php';
$sql = "SELECT * FROM appointments where DATE_FORMAT(appoint_date,'%Y-%m-%d') = '2005-04-09' and status = 'Waiting' and user_id in ('test')";
$resultappoint = mysql_query($sql) or die('Error, query failed $sql');
$row = mysql_fetch_object($resultappoint);
$set_waiting_time=$row->waitingtime;
list($new_year,$new_month,$new_day,$new_hour,$new_min,$new_sec) = split('[-: ]', $set_waiting_time);
$formatted_waiting_time = "$new_hour,$new_min,$new_sec,$new_month,$new_day,$new_year";

$sys_date_for_difference = date("g,i,s,m,j,Y");

print $sys_date_for_difference;
print '<hr>';
print $formatted_waiting_time;
$dateDiff = mktime($formatted_waiting_time) - mktime($sys_date_for_difference);

echo '<br />Years Difference   = '. floor($dateDiff/365/60/60/24);
echo '<br />Months Difference  = '. floor($dateDiff/60/60/24/7/4);
echo '<br />Weeks Difference   = '. floor($dateDiff/60/60/24/7);
echo '<br />Days Difference    = '. floor($dateDiff/60/60/24);
echo '<br />Hours Difference   = '. floor($dateDiff/60/60);
echo '<br />Minutes Difference = '. floor($dateDiff/1000);
Output of screen is like this

2,38,17,04,9,2005
--------------------------------------------------------------------------------
08,55,00,04,09,2005
Years Difference = 0
Months Difference = 0
Weeks Difference = 0
Days Difference = 0
Hours Difference = 6
Minutes Difference = 21

Time difference calculation is not right due to reason that there is '0' is start of hour and month. database date needed to formatted please tell me how to do that?

Posted: Thu Apr 14, 2005 4:56 pm
by feyd
mktime() does not accept an string containing all the arguments for it. They must be sent seperated in some fashion.