Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compare dates in php and sql?

Tags:

php

mysql

I want to make a notification system. Shortly.. to compare two dates, the only problem is that i want to compare the months. to see if a month or two have passed from last notification.

i want to use one or two months from an entry in a mysql database.

the client must select when the notification must come, one or two months.

thank you, Sebastian

like image 944
sebastian Avatar asked Dec 14 '25 11:12

sebastian


1 Answers

Your statement 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 to the current time "NOW()".

That works with DATE, DATETIME and TIMESTAMP columns.

like image 94
2ndkauboy Avatar answered Dec 17 '25 02:12

2ndkauboy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!