ในการแปลงตัวเลขเป็นชื่อเดือนใน PHP โค้ดจะเป็นดังนี้−
ตัวอย่าง
<?php
$date = "2019-11-11";
echo "Displaying date...\n";
echo "Date = $date";
$month_name = date("F", mktime(0, 0, 0, 11, 10));
echo "\nMonth = ".$month_name."\n";
echo "\nDisplaying updated date...\n";
echo date('Y-m-d', strtotime($date. ' + 20 days'));
?> ผลลัพธ์
สิ่งนี้จะทำให้เกิดผลลัพธ์ดังต่อไปนี้−
Displaying date... Date = 2019-11-11 Month = November Displaying updated date... 2019-12-01
ตัวอย่าง
เรามาดูตัวอย่างอื่นกัน −
<?php
$date = "2019-11-11";
echo "Displaying date...\n";
echo "Date = $date";
$month_name = date("F", mktime(0, 0, 0, 11, 10));
echo "\nMonth = ".$month_name."\n";
echo "\nDisplaying updated date...\n";
echo date('Y-m-d', strtotime($date. ' + 20 days'));
$val = DateTime::createFromFormat('!m', 12);
$month_name2 = $val->format('F');
echo "\nMonth = ".$month_name2."\n";
?> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Displaying date... Date = 2019-11-11 Month = November Displaying updated date... 2019-12-01 Month = December