Jay2391 Posted November 17, 2007 Share Posted November 17, 2007 I have a date 11-07-2007 22:06 and i want to know how to calculate 4 hours ahead and create a count down system $date_now $date_4hours $countdown = $date_now - $date_4hours; Link to comment https://forums.phpfreaks.com/topic/77686-calculate-date-help/ Share on other sites More sharing options...
axiom82 Posted November 17, 2007 Share Posted November 17, 2007 // Run Once: Set Session Date Range // if (!isset ($_SESSION['date'])){ // Set Session Date Start // $query = mysql_query ("SELECT now() AS start"); $date = mysql_fetch_assoc ($query); $_SESSION['date']['start'] = $date['start']; // Set Session Date End // $query = mysql_query ("SELECT date_add('{$_SESSION['date']['start']}', interval 4 hour) AS end"); $date = mysql_fetch_assoc ($query); $_SESSION['date']['end'] = $date['end']; } // Retrieve Remaining Date Difference // $query = mysql_query ("SELECT time_diff(now(), '{$_SESSION['date']['end']}') AS remaining"); $date = mysql_fetch_assoc ($query); // Print Calculation // echo $date['remaining']; Link to comment https://forums.phpfreaks.com/topic/77686-calculate-date-help/#findComment-393267 Share on other sites More sharing options...
Jay2391 Posted November 17, 2007 Author Share Posted November 17, 2007 i got a database error??? Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\web\xampp\htdocs\mdo_main\t.php on line 7 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\web\xampp\htdocs\mdo_main\t.php on line 7 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\web\xampp\htdocs\mdo_main\t.php on line 8 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\web\xampp\htdocs\mdo_main\t.php on line 12 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\web\xampp\htdocs\mdo_main\t.php on line 12 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\web\xampp\htdocs\mdo_main\t.php on line 13 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\web\xampp\htdocs\mdo_main\t.php on line 19 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\web\xampp\htdocs\mdo_main\t.php on line 19 Warning: mysql_fetch_assoc(): supplied argument is not Link to comment https://forums.phpfreaks.com/topic/77686-calculate-date-help/#findComment-393294 Share on other sites More sharing options...
Jay2391 Posted November 17, 2007 Author Share Posted November 17, 2007 i included my user name and this is what i got know Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\web\xampp\htdocs\mdo_main\t.php on line 20 Link to comment https://forums.phpfreaks.com/topic/77686-calculate-date-help/#findComment-393297 Share on other sites More sharing options...
axiom82 Posted November 17, 2007 Share Posted November 17, 2007 You have to start a connection to MySQL before running queries...even if they do not access data records. $mysql['host'] = 'localhost'; $mysql['user'] = 'your-user'; $mysql['pass'] = 'your-pass'; $mysql['db'] = 'your-database'; $mysql['connect'] = mysql_connect ($mysql['host'], $mysql['user'], $mysql['pass']); mysql_select_db ($mysql['db'], $mysql['connect']); Link to comment https://forums.phpfreaks.com/topic/77686-calculate-date-help/#findComment-393299 Share on other sites More sharing options...
axiom82 Posted November 17, 2007 Share Posted November 17, 2007 Fix the time_diff to timediff..here is the correction for Line 20... query = mysql_query ("SELECT timediff(now(), '{$_SESSION['date']['end']}') AS remaining"); Link to comment https://forums.phpfreaks.com/topic/77686-calculate-date-help/#findComment-393300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.