How to compare dates in php and sql?

I want to create a notification system. Soon ... to compare the two dates, the only problem is that I want to compare the months. to find out if a month or two has passed since the last notification.

I want to use one or two months from a record in mysql database.

the client must choose when a notification should appear, one or two months.

Thank you Sebastian

+3
source share
2 answers

Your expression should look like this:

SELECT * FROM table WHERE date_column + INTERVAL 1 MONTH >= NOW()

You add 1 (or 2) month to the date of the column in which the date is stored, and compare it with the current time "NOW" ().

This works with the DATE, DATETIME and TIMESTAMP columns.

+2
source

datetime MySQL.

, " ", , "" - ; 30 , - 31, 28. "30 ", , , 86 400 ( ).

0

Source: https://habr.com/ru/post/1749823/


All Articles