Sunday, July 17, 2011

How to get number of days between two dates using MySQL

While developing web application , in many many places we face the problem where we can use only MYSQL and get the number of number of days between two given dates using MySQL.
Syntax - DATEDIFF(FirstDate,SecondDate)

This function will calculate the difference bretween two dates and give the out put in number of days. It will give the result positive only if first date is grater than second date. If Second date is greater than First date than it will give the negative result.
Query : SELECT DATEDIFF(’2010-01-05′, ’2009-12-15′);
Result : 21
Query : SELECT DATEDIFF(’2009-12-15′, ’2010-01-05′);
Result : -21
hope this will  help full for some. :D
let me know if any solution require !



Post a Comment

Any Questions or Suggestions ?


Professional & Experienced Freelance Developer From India, Technologist, Software Engineer, internet marketer and Open Sources Developer with experience in Finance, Telecoms and the Media. Contact Me for freelancing projects.

Enter your email address:

Delivered by FeedBurner

PHP Freelancer India - Google+