Jump to content

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:

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

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.
Link to comment
https://forums.phpfreaks.com/topic/15147-difference-in-timestamps/
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).
[code]
<?PHP
$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.
?>
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.