Skip to content
Advertisement

SELECT timestamp MATCH DAY 25 or 26

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:

SELECT * FROM table WHERE timestamp MATCH DAY 25

Or do I need this:

$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

SELECT * FROM table WHERE DAYOFMONTH(timestamp) = $day

And if you have more than one day to look for

SELECT * FROM table WHERE DAYOFMONTH(timestamp) IN (25,26,27);
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement