Reputation: 334
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.
Upvotes: 0
Views: 1018
Reputation: 5665
Keep it simple. Not sure exactly what you are trying to do.
SELECT * FROM schedule WHERE `dateTime` < '2015-01-31 10:00:00'
Upvotes: 1
Reputation: 8659
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
Upvotes: 1