Reputation: 841
I have data in end_date
field like 29 August 2016 - 18:45
.
I want to write a query where end_date
matches the current server date time.
I am using this
select * from round_dates where end_date = CURDATE()
CURDATE()
matches the today date but I need to match the time also
Upvotes: 0
Views: 39
Reputation: 344
NOW()
return the current datetime stamp of Mysql Server.
Whereas CURDATE()
returns the date stamp only.
So, you can use this below Query
SELECT * FROM table_name WHERE STR_TO_DATE(start_date, '%e %M %Y - %k:%i') = NOW()
Upvotes: 1
Reputation: 440
select *
from round_dates
where end_date = DATE_FORMAT(now(),'%e %M %Y - %k:%i')
Upvotes: 2
Reputation: 34232
Use MySQL's str_to_date() or date_format() functions to convert either the stored data to date format or the date format to the currently stored format.
Side note: I would rather do a one-off exercise of converting that field's data to standard MySQL datetime format, than trying to fix any queries relying on this field.
...where str_to_date(end_date,'%e %M %Y - %k:%i')=now()
Upvotes: 0