How to find a start date & end date of any given year & month

前端 未结 8 1440
庸人自扰
庸人自扰 2021-01-04 05:18

I have problem in php find start date & end date of month & year , when i know the year and month ?

ex:

input - > year = 2011 , month = 0         


        
相关标签:
8条回答
  • 2021-01-04 06:11

    hi Try this way u can do it

    function firstOfMonth() {
    return date("m/d/Y", strtotime(date('m').'/01/'.date('Y').' 00:00:00'));
    }
    
    function lastOfMonth() {
    return date("m/d/Y", strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00'))));
    }
    
    $date_start = firstOfMonth();
    $date_end  = lastOfMonth();`
    
    0 讨论(0)
  • 2021-01-04 06:15

    Start date will always be 1 and you can find the end date with the following function.

    cal_days_in_month(CAL_GREGORIAN, $month, $year);
    

    reference:

    cal_days_in_month ( int $calendar , int $month , int $year ) : int

    0 讨论(0)
提交回复
热议问题