D
D
DrDiza2014-01-21 08:03:20
MySQL
DrDiza, 2014-01-21 08:03:20

Why does SELECT date( "2014-01-01" ) - date( "2013-12-31" ) return 8870?

Why does a query in mysql SELECT date( "2014-01-01" ) - date( "2013-12-31" ) return 8870 ?
MySQL version 5.1.66.
OS: FreeBSD 8.2-RELEASE
The date on the server is set correctly.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
akashtrih, 2014-01-21
@akashtrih

And what did you want to do by calling the DATE() function for dates that no longer have time? In fact, you have the difference of the strings "2014-01-01" and "2013-12-31", which are converted to the numbers 20140101 and 20131231, the difference of which is 8870.
To get the number of days between two dates, you can use the DATEDIFF function () :
SELECT DATEDIFF('2014-01-01','2013-12-31');

D
DrDiza, 2014-01-21
@DrDiza

no, I had to select records older than 60 days.
did like this:
SELECT TO_DAYS(now()) - TO_DAYS(timefrom)) > 60;
those. the to_days function operates on dates, and the date function operates on numbers.
thank you very much.

D
DrDiza, 2014-01-22
@DrDiza

I don’t know why, but in terms of processing time, the option:
(TO_DAYS( now( ) ) - TO_DAYS( timefrom )) < 60
and the option:
DATE_SUB( CURDATE( ) , INTERVAL 60 DAY ) < timefrom
are exactly the same, although the first option performs much more calculations .
while the table has ~1,089,909 rows

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question