Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

Quick way to get the number of days in a month with PHP

David Carr

PHP & MySQL Tutorials

    I’m building a php calendar and need to know the total number of days in a month in the past I've used: 

    echo cal_days_in_month(CAL_GREGORIAN, 2, 2017);

    For the current month you can use:

    echo date('t');

    Or for a more a date based approach:

    echo date('t', strtotime('2017-02-01')); 

     

    Laravel Modules Book by David Carr

    Help support the blog so that I can continue creating new content!

    Subscribe to my newsletter

    Subscribe and get my books and product announcements.

    © 2009 - 2022 DC Blog. All code MIT license. All rights reserved.