How to get number of days between two dates using MySQL

mysql-database-freelancer-developer-2

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.

Example:

Query : SELECT DATEDIFF('2010-01-05', '2009-12-15');
Result : 21

Query : SELECT DATEDIFF('2009-12-15', '2010-01-05');
Result : -21

Look at below links for great magic tricks.

To know more about programming ,MYSQL database , php info , php editor , programming php ,Open-source, php help and php script , subscribe to our feed by entering email address below. You will get updates via email about every tutorial posted on this site . It will not take more than a sec.

Enter your email address:
 
Feel free to ask any question. Just leave your comment below and we will answer your comment with in 24 hours.

About Rakshit Patel
I am PHP Freelancer, Rakshit Patel AKA WordPress Freelancer working as PHP Programmer India. I am here to share all my developing knowledge, quick coding techniques, quick solutions to save your time and help you guys for any issue or bug fixing. If you have any PHP, WordPress, Magento related work, please contact me. I am interested for the work.

5 Comments on How to get number of days between two dates using MySQL

  • shail
    December 21, 2009 at 6:54 pm

    In which formatt date is there?

  • shail
    December 22, 2009 at 12:24 am

    In which formatt date is there?

  • Rakshit Patel
    December 22, 2009 at 6:57 am

    Its YYYY-MM-DD format : Standard MYSQL date format so you have to pass the date parameters in this format only.

    If you will pass date in YYYY-MM-DD H:i:s format than also during calculation , it will consider only YYYY-MM-DD only.

  • Rakshit Patel
    December 22, 2009 at 12:27 pm

    Its YYYY-MM-DD format : Standard MYSQL date format so you have to pass the date parameters in this format only.

    If you will pass date in YYYY-MM-DD H:i:s format than also during calculation , it will consider only YYYY-MM-DD only.

  • Nannette
    March 24, 2013 at 2:33 am

    Your own blog post, Modern Window Treatments “How to get number of days between two dates using MySQL | Programming Facts -PHP
    Freelancer-Indian Freelancer” was indeed truly worth commenting down here in the
    comment section! Just needed to announce u did a very good work.
    Thanks for your effort ,Lenard

Leave a Reply

Your email address will not be published. Required fields are marked *

Sponsors

Sponsors

Recommended

DHgate Computers
DHgate.com - Computers, Cell Phones & more
  • We find everbuying built in php and use css to control the style.

About Author

PHP Freelancer

PHP Freelancer I am PHP Freelancer, Rakshit Patel working as PHP Programmer India. I am here to share all my developing knowledge with you people. For Hire PHP Developer India, contact me.
Follow on twitter: @raxit4u2

Get Free Programming Tutorials:

Become a Fan

Popular Topics

Recent Posts

Most Popular

Recent Comments

Get a Free Quote
$
$
$
Security Question: 3 + 8 = ?
$
 
Listing all pages