Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

วิธีหาวันแรกของสัปดาห์ใน PHP


เพื่อหาวันแรกของสัปดาห์ใน PHP โค้ดมีดังนี้ −

ตัวอย่าง

<?php 
    $res = date('l - d/m/Y', strtotime("this week")); 
    echo "First day = ", $res; 
?>

ผลลัพธ์

จะผลลัพธ์ดังนี้ −

First day = Monday - 09/12/2019

ตัวอย่าง

มาดูตัวอย่างอีกอย่าง −

<?php 
    echo "Displaying Sunday as first day of a week...\n"; 
    $res = date('l - d/m/Y', strtotime("sunday 0 week")); 
    echo "First day (next week) = ", $res; 
?>

ผลลัพธ์

จะผลลัพธ์ดังนี้ −

Displaying Sunday as first day of a week... First day (next week) = Sunday - 15/12/2019