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开发者_StackOverflow中文版 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
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.
You can compare months of two datetime
columns inside of MySQL.
The only computer-related shortcoming of saying "a month has passed" is that a "month" is an arbitrary unit of time; some have 30 days, others have 31 and one even has 28. I would suggest using the logic of "30 days has passed" because it is based on a set unit of time, a day, which is 86,400 seconds long (with negligible error of course).
精彩评论