Jump to content


Difference in Timestamps

  • Please log in to reply
1 reply to this topic

#1 gladiator83x

  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 20 July 2006 - 02:15 PM

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.

#2 ChaosXero

  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 20 July 2006 - 02:29 PM

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users