I am trying to get all timestamps from the Database, that match the day of the month that are specifyed. All i have is the day numbers(25, 26, 27 ect.) and not a full date strings(25/12/2018, 26/12/2018 ect.)
Is there a way to do:
JavaScript
x
SELECT * FROM table WHERE timestamp MATCH DAY 25
Or do I need this:
JavaScript
$day = '25';
$month = date('M');
$year = date('Y');
$timestamp = strtotime($day . '-' . $month . '-' . $year);
SELECT * FROM table WHERE timestamp=$timestamp
It will always be the current month and year, only the day changes.
Advertisement
Answer
Using the DAYOFMONTH()
function would do this for you
JavaScript
SELECT * FROM table WHERE DAYOFMONTH(timestamp) = $day
And if you have more than one day to look for
JavaScript
SELECT * FROM table WHERE DAYOFMONTH(timestamp) IN (25,26,27);