Get all days and date for a given month

后端 未结 9 1517
天涯浪人
天涯浪人 2021-02-10 08:17

Would like to retrieve all days and date for a given month. Have this currently which shows all the days for the current month, but how do I parse in a specified month instead?<

相关标签:
9条回答
  • 2021-02-10 08:57

    try this

    $month = "05";
    $year = "2014";
    
    $start_date = "01-".$month."-".$year;
    $start_time = strtotime($start_date);
    
    $end_time = strtotime("+1 month", $start_time);
    
    for($i=$start_time; $i<$end_time; $i+=86400)
    {
       $list[] = date('Y-m-d-D', $i);
    }
    
    print_r($list);
    

    See Demo

    0 讨论(0)
  • 2021-02-10 08:58

    try this

    $list=array();
    $month = 12;
    $year = 2014;
    
    for($d=1; $d<=31; $d++)
    {
        $time=mktime(12, 0, 0, $month, $d, $year);          
        if (date('m', $time)==$month)       
            $list[]=date('Y-m-d-D', $time);
    }
    echo "<pre>";
    print_r($list);
    echo "</pre>";
    
    0 讨论(0)
  • 2021-02-10 09:02

    you may use $list[]=date('Y-M-D', $time);

    Reference

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