PDA

View Full Version : php and mysql timestamp


whitedragon101
07-02-2009, 12:33 AM
Here is some code I am trying to use to find the difference in days between 2 mysql time stamps. I have tried to find tutorials but the trouble is the million or so examples only show some syntax not a full example of the mysql and php working together on a page and I am making some mistakes.

from_date and to_date are both TIMESTAMP's


mysql_select_db($database_myconnect, $myconnect);
$query_job_req_set = sprintf("SELECT * FROM job_request WHERE job_id = %s", GetSQLValueString($colname_job_req_set, "int"));
$job_req_set = mysql_query($query_job_req_set, $myconnect) or die(mysql_error());
$row_job_req_set = mysql_fetch_assoc($job_req_set);
$totalRows_job_req_set = mysql_num_rows($job_req_set);


$date1 = $row_job_req_set['bricklayer_from_date'];
$date2 = $row_job_req_set['bricklayer_to_date'];
$queryDateDiff = sprintf("SELECT TO_DAYS($date1) - TO_DAYS($date2) FROM job_request WHERE job_id=%s", GetSQLValueString($colname_job_req_set, "int"));
$date_req_set = mysql_query($queryDateDiff, $myconnect) or die(mysql_error());
$totalRows_date_req_set = mysql_num_rows($date_req_set);

echo "number of rows $totalRows_date_req_set";
$date_row = mysql_fetch_row($date_req_set);

echo " The result is $date_row[0]";

The output is currently:

hello this is 1 The result is