Latest Post

Error: No input file specified.

While trying to run a codeigniter app the other day I came across this error just after I had finished uploading the files and making the ne...

Monday, February 22, 2010

Get number of days from a given mysql date field

Using mysql's inbuilt TO_DAYS() and CURDATE() functions one can determine the number of days from a given mysql date field to date.


SELECT date_field, CURDATE() AS Current_Date, (TO_DAYS( CURDATE() ) - TO_DAYS( date_field )) as difference FROM table_name


SAMPLE OUTPUT OF THIS WOULD BE :


date_field Current_Date difference
---------- ------------ ------------
2010-02-11 2010-02-22 11
2010-02-10 2010-02-22 12

2 comments:

  1. Glad you are enjoying. Will keep posting useful articles.

    ReplyDelete

Chitika Ads