# Why won't this work as the solution (just reversing w1 and w2)

• SELECT w2.Id from Weather w1, Weather w2 where dateDiff(w1.Date,w2.Date)=1 and w2.Temperature>w1.Temperature

• because dateDifference gives the absolute output so either w1 date is later or w2 it always gives 1 for 1 day difference. for example:
if w1.date =1990-05-02
w2.date =1990-05-03
this gives 1...
but
w1.date =1990-05-03
w2.date =1990-05-02
this also gives 1 ..
and you are printing id of only w2 instance of weather..

• You want w1 be the earlier date and w2 be the later date, right? For example the 5th and the 6th of a month? Do you think `5 - 6 = 1`? It's `-1`. So don't ask for

``````dateDiff(w1.Date,w2.Date) = 1
``````

but for

``````dateDiff(w2.Date,w1.Date) = 1
``````

or

``dateDiff(w1.Date,w2.Date) = -1``

• You're wrong, it doesn't give the absolute value (unless it's already non-negative, of course).

• It seems SQL and mySQL have different datediff functions.

• Which SQL, and how does it differ?

• Well, when I google "SQL Datediff", most of the websites show the difference between two dates will be an absolute value. The function also takes a third parameter indicating the time unit which doesn't apply for Datediff in mySQL, i.e. Datediff(day, "2015-10-02", "2015-10-03") = 1.

• I had googled as well and couldn't find one with absolute value. Can you show one of those?

• http://www.w3schools.com/sql/func_datediff.asp
My mistake saying it takes absolute value. It's just the order of the dates is opposite for SQL server. I guess the asker just also looked at the Datediff example for SQL server.

• Hmm, interesting that they differ that way...

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.