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

194 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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.