Get names of month, weekday of the year for any date value in PHP


To get the names of month, weekday, of the year for any date value in PHP, use the function getDate();


Example:

$datePieces = getDate(strtotime($mydate));




echo "Month name: ".$datePieces['month'];  
echo "Weekday name: ".$datePieces['weekday'];

Make sure to use quotes for the key value like $datePieces['month'] instead $datePieces[month], since it would throw : Notice: Use of undefined constant .... 

The associative array $datePieces contains all of the following:




Array
(
    [seconds] => 40
    [minutes] => 58
    [hours]   => 21
    [mday]    => 17
    [wday]    => 2
    [mon]     => 6
    [year]    => 2003
    [yday]    => 167
    [weekday] => Tuesday
    [month]   => June
    [0]       => 1055901520
)

No comments:

Post a Comment

Detectron2 + PyTorch CPU : Fix Install issue

Detectron2 + PyTorch CPU ❌ The error $ pip install -q --extra-index-url https://download.pytorch.org/whl/cpu torch torchvision $ pip inst...