Select all data from MySQL where varchar date greater than today ?

To select all event from MySQL varchar date, that start from tomorrow on wards we have a easy method via usingĀ  STR_TO_DATE function.It convert stored date and compare with CURDATE() function

Here in this example i am even table in that table event start date is stored in the filed named event_start_time, my requiremnt is to fetch all event that is greater than today date and i need in the event date Asending order

See MySQL query

SELECT * FROM event WHERE STR_TO_DATE(event_start_time, '%d-%m-%Y') > CURDATE() ORDER BY STR_TO_DATE(event_start_time,'%d-%m-%Y') Asc

To Fetch coming 7 days data event

SELECT * FROM event WHERE STR_TO_DATE(event_start_time, '%d-%m-%Y') > CURDATE() AND STR_TO_DATE(event_start_time, '%d-%m-%Y') <= CURDATE() + INTERVAL 7 DAY 

To Fetch coming one month data event

SELECT * FROM event WHERE STR_TO_DATE(event_start_time, '%d-%m-%Y') > CURDATE() AND STR_TO_DATE(event_start_time, '%d-%m-%Y') <= CURDATE() + INTERVAL 30 DAY 

To fetch Today’s Event

SELECT * FROM event WHERE STR_TO_DATE(event_start_time, '%d-%m-%Y') = CURDATE()

Leave a Reply

Your email address will not be published. Required fields are marked *