Reputation: 15
Hi I am trying to select row's where the datefiled eg 11-11-2011 12:00
is equal to the current hour.
Sorry, to add it should match the whole date but round to the hour.
Here's what I have so far :
SELECT * FROM emails WHERE SUBSTRING(datetosend,0,12) = SUBSTRING(NOW(),0,12)
Upvotes: 1
Views: 1226
Reputation: 69439
Try this:
SELECT * FROM x where SUBSTRING(d,0,12)= SUBSTRING(date_format(NOW(), '%d-%m-%Y %I' ),0,12 )
Upvotes: 0
Reputation: 809
SELECT *
FROM emails
WHERE DATE_FORMAT(datetosend, '%Y-%m-%d %H') = DATE_FORMAT(NOW(), '%Y-%m-%d %H');
This sql doesn't care which date format your column is using.
Upvotes: 2
Reputation: 13509
Try this:-
SELECT *
FROM emails
WHERE HOUR(datetosend) = HOUR(NOW());
Upvotes: 0