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

Resolving Package Conflict with Level-Zero Installation; Fixing dpkg Error

Preparing to unpack level-zero_1.20.2+u24.04_amd64.deb ... Unpacking level-zero ( 1.20.2 ) ... dpkg: error processing archive level-zero_1....