Date comparison.

MySQL how to compare the difference between two dates of the month? Acute

Started by Dana at December 17, 2016 - 4:58 PM

What is the difference between the month between two date rule?

2013-10-01 and 2013-09-30 are the number of months?
This in MYSQL is difficult to define, usually write their algorithm.

Posted by Bartley at December 19, 2016 - 5:56 PM

zz

select timediff('23:40:00', ' 18:30:00'); Two time subtraction
SELECT substring( timediff('23:40:00', ' 18:30:00'),1,5) ----"05: 10"Subtraction return hours: minutes
select datediff('2008-08-08', '2008-08-01'); - 7 - two date subtraction
select TO_DAYS('2008-09-08')-TO_DAYS('2008-08-08') - two date subtraction
SELECT substring( '2009-06-17 10:00:00', 1, 10 ) Extracted from the datetime date "."

Posted by Armstrong at December 20, 2016 - 6:29 PM

The date difference, divided by 30 ? :)

Posted by Adair at December 24, 2016 - 7:15 PM

This is not a reasonable amount. For example, '2013-01-31' and '2013-02-29' is a month apart. How to let the computer judgment?

Posted by Dana at January 02, 2017 - 7:22 PM

Is not reasonable, this is a relatively complex calculation rules, be careful and rational design.

Posted by Adair at January 03, 2017 - 9:33 PM

Can not do:
According to the two date two years Year1 Month1 date, Year2 Month1
According to the calculated difference years (Year1-Year2)*12
According to the calculation of the difference on the monthly (Month1-Month1)
Then a total of two differential

The calculation method to a function call

Posted by Angelia at January 07, 2017 - 10:12 PM

Also consider whether to date a month apart

Posted by Adair at January 07, 2017 - 10:24 PM

This problem has no solution.

Posted by Bartley at January 08, 2017 - 8:06 PM

Why MySQL can calculate the date and 1 months date, why not reverse calculation between 2 dates are integer months? This.

Posted by Dana at January 12, 2017 - 9:05 PM