Search code examples
mysqlsqlsqldatetime

PURE SQL get days beteen given date and current date, without functions


I need to get number of days between 2 dates, a given one and current date.

But in pure SQL, I mean without usign functions, it is possible?

For exaple

SELECT days (t.givenDate) - days (current date) FROM table t

Have you any idea?

Thaks a lot.


Solution

  • The built-in function is datediff(). The equivalent for the above is:

    SELECT datediff(t.givenDate, curdate()) FROM table t;
    

    Normally, givenDate would be in the past and you would want the arguments in the other order.