Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare date to today's date and return number of days

I am using MySQL.

I am trying to compare a date that is in a datetime field to today's date and return the number of days difference [i.e. today - column = no. of days]

Is that possible? How would I do it?

like image 718
GiANTOnFire Avatar asked Jan 28 '26 11:01

GiANTOnFire


1 Answers

I think we need more information from your side, like the query you are using and what you tried so far, but maybe this can help you out:

SELECT 
    DATEDIFF('2014-02-20 00:00:00', NOW()); //return 7

In this case, you should add a 'FROM table' and replace the date in this query to the datetime column. Something like this:

SELECT 
    DATEDIFF(datetimefield, NOW())
FROM
    tablename
like image 124
Benz Avatar answered Jan 31 '26 03:01

Benz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!