Reputation: 193
I have a tabel in MYSQL database that has 2 columns.
1- start_date
2- end_date
the above columns both hold DATETIME like so:
start_date end_date
2019-10-03 13:30:00 2020-10-03 23:30:00
I need to select from the MYSQL table ONLY if the current date
is between the start_date
and end_date
.
So i tried this MYSQL Query:
SELECT * FROM table WHERE `end_date` >= CURDATE() AND `start_date` <= CURDATE()
but this doesn't work and doesn't return anything from the database even thogh the the current date is between the start_date and end_date.
Could someone please advice on this?
Upvotes: 1
Views: 56
Reputation: 15296
Q: I need to select from the MYSQL table ONLY if the current date is between the start_date and end_date.
Try this.
SELECT * FROM `table` WHERE CURDATE() between start_date and end_date
Convert it with date before because you're using their timestamp.
SELECT * FROM `table` WHERE CURDATE() between date(start_date) and date(end_date)
Or
SELECT * FROM `table` WHERE NOW() between start_date and end_date
Upvotes: 1
Reputation: 88
Using SQL date function in query
SELECT * FROM user WHERE date(end_date) >= CURDATE() AND date(start_date) <= CURDATE()
Upvotes: 1
Reputation: 5410
try this
SELECT * FROM table
WHERE start_date >= '2019-10-03 13:30:00'
AND end_date <= '2020-10-03 23:30:00'
Upvotes: 0