date diff calculations didn't come right

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
atypk
Forum Newbie
Posts: 4
Joined: Sat Nov 22, 2003 4:06 am

date diff calculations didn't come right

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mktime() does not accept an string containing all the arguments for it. They must be sent seperated in some fashion.
Post Reply