Get all days and dates for a given month

I would like to get all the days and dates for this month. Is there a current one that shows all the days of the current month, but how can I analyze in the specified month instead?

$list=array();
for($d=1; $d<=31; $d++)
{
    $time=mktime(12, 0, 0, date('m'), $d, date('Y'));
    if (date('m', $time)==date('m'))
        $list[]=date('Y-m-d-D', $time);
}
echo "<pre>";
print_r($list);
echo "</pre>";
+5
source share
7 answers

try it

$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>";
+17
source

try it

$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

+9
source

- ,

function getDaysInYearMonth (int $year, int $month, string $format){
  $date = DateTime::createFromFormat("Y-n", "$year-$month");

    $datesArray = array();
    for($i=1; $i<=$date->format("t"); $i++){
        $datesArray[] = DateTime::createFromFormat("Y-n-d", "$year-$month-$i")->format($format);
    }

 return $datesArray;
}
+2

.

$y_m = '2018-10'; // set year and month.

$list = array();
$d = date('d', strtotime('last day of this month', strtotime($y_m))); // get max date of current month: 28, 29, 30 or 31.

for ($i = 1; $i <= $d; $i++) {
    $list[] = $y_m . '-' . str_pad($i, 2, '0', STR_PAD_LEFT);
}

echo '<pre>';
print_r($list);
echo '</pre>';
0
$days = cal_days_in_month( 0, $month, $year);

cal_days_in_month: .
- "":

0 CAL_GREGORIAN -
1 CAL_JULIAN -
2 CAL_JEWISH -
3 CAL_FRENCH -

http://php.net/manual/en/function.cal-days-in-month.php

http://php.net/manual/en/function.cal-info.php

0
source
$list=array();
$d = 13;
$year = 2019;

for($m=1; $m<=12; $m++)
{
    $time=mktime(12, 0, 0, $m, $d, $year);          
    if (date('m', $time)==$m)       
        $list[]=date('D-d-m-Y', $time);
    }

In this you can specify a special number and release all days of the year with the same number. For example, I wanted to pour out all 13 of the month. (if you want to find every Friday the 13th that you should use)

0
source

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

Link

-2
source

Source: https://habr.com/ru/post/1541404/


All Articles