简体   繁体   中英

PHP MySQL TIMESTAMPDIFF with seconds not working

I have been testing this for hours and can not seem to get it to work. Below is a simplified version of what I'm working with. Each time I test it I get 0 results. I have many entries in the database that are before and after :start.

$bind = array(':start'=>'01-31-2015 10:00 AM' );
$select  = "TIMESTAMPDIFF(SECOND,dateTime,:start)>0";
$results = $db->select("schedule", $select, $bind);

I suppose I should give the plain version which is as follows.

SELECT * FROM schedule WHERE TIMESTAMPDIFF(SECOND,dateTime,'01-31-2015 10:00 AM')>0

In the select above dateTime would be in the same format as :start.

I don't know if I have to use a specific date format but I would like to use the existing format if possible.

Wrap TIMESTAMP() around your date string as sometimes MySQL doesn't interpret it as a date until you do, and you get weird results. Also the date format for MySQL is

YYYY-MM-DD HH:MM:SS

SELECT * FROM schedule WHERE TIMESTAMPDIFF(SECOND,dateTime,TIMESTAMP('2015-01-31 10:00:00'))>0

Keep it simple. Not sure exactly what you are trying to do.

SELECT * FROM schedule WHERE  `dateTime` < '2015-01-31 10:00:00'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM