Jump to content


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


Difference in Timestamps

Recommended Posts

Hi All,

I was wondering if someone could help me out taking the difference of timestamps in mysql or php. According to this website:


There is a DATEDIFF function that should return expr1-expr2.

When I try to use it I get an error that states: Parse error: parse error, unexpected T_STRING.

The tidbit of code that I am using for this can be used for this is:

$t=SELECT DATEDIFF ($col_value,$creation_ts);
echo $t;

I tried putting quotes around everything, but that still didn't work--any suggestions?
The format of the 2 dates is 2006-07-20 09:30:38.

Share this post

Link to post
Share on other sites
You have to run the DATEDIFF from a query as it is a mySQL function.  In this case echoing would simply output SELECT DATEDIFF ($col_value,$creation_ts); (which would need quotes XD).
$t="SELECT DATEDIFF ( ". $col_value . " ,". $creation_ts .")";
$diff = mysql_query($t);
// I dont know how this should be returned, you may need a mysql_fetch_* of some sort.

Share this post

Link to post
Share on other sites


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.