Jump to content

calculate date help


Jay2391

Recommended Posts


// 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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.