Forum Moderators: open

Message Too Old, No Replies

Date Difference in MySQL

         

otem

6:58 pm on Feb 16, 2007 (gmt 0)

10+ Year Member



Hello,

I'm trying to update a row so that the value of a cell (shown)is equal to the date difference between the timestamp in another cell (time)and the current time.

I'm using MySQL, and this is what I have, but it doesn't seem to work.

Any suggestions? Thanks.

mysql_query("UPDATE mytable SET shown=DATEDIFF(time,'".date("Y-m-d H:i:s")."') WHERE ip='$ip'");

otem

7:37 pm on Feb 16, 2007 (gmt 0)

10+ Year Member



I made some modifications:

I renamed time to first_shown incase time was a reserved variable.

mysql_query("UPDATE mytable SET shown=DATEDIFF(first_shown,'".date("Y-m-d H:i:s")."') WHERE ip='$ip'");

I saw something about CURRENT_DATE. Should I be using that instead of the clunky date expression above?

Thanks

coopster

5:06 pm on Feb 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What isn't working? DATEDIFF will return the value in days from one date to the other.