Skip to content

Conversation

mecab
Copy link
Contributor

@mecab mecab commented Jan 31, 2018

Subtracting numbers from datetime causes wrong value, or raises error depending on MySQL version/configurations. It leads deleting notification wrongly or failed to do so.

This PR solves above issue by using INTERVAL to make appropriate value for date calculation.

Below confimed in MySQL8.0

mysql> select NOW() \G
*************************** 1. row ***************************
NOW(): 2018-01-01 13:25:56

mysql> select NOW() - 7 * 24 * 60 * 60\G
*************************** 1. row ***************************
NOW() - 7 * 24 * 60 * 60: 20180100527811

The result 20180100527811 is wrong. It is 20180101132611(string transformation by YYYYMMDDHHmmSS) - 7*24*60*60

mysql> select NOW() - INTERVAL 7 DAY\G
*************************** 1. row ***************************
NOW() - INTERVAL 7 DAY: 2017-12-25 13:28:18

I tried in MySQL 5.7 and had same result. And it ends up with error when this calculation used in WHERE clause.

Subtracting numbers from datetime causes wrong value, or raises error depending on MySQL version/configurations
@TheSerapher TheSerapher merged commit 6dab6be into MPOS:development Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants