How To Get Day Name From Date In Php

Example 1: Extract Day Name From Static Date
<?php
 
    $datetime = DateTime::createFromFormat('d/m/Y', '05/06/2021');
    echo $datetime->format('l');
    // echo $datetime->format('D');  // Output: Sat
--------------------------------------------------------------------------------

    Example 2: Extract Day Name Using date() Function

    <?php
    // Date Format: Y/m/dd
    $paymentDate = '2021/06/05';;
    echo $day = date('l', strtotime($paymentDate));
    // echo $day = date('D', strtotime($paymentDate));  // Output: Sat
    ?>
-----------------------------------------------------------------------------------

    Example 3: Extract Day Name Using date_format() Function

    <?php
    // Date Format: Y/m/dd
    $date = date_create("2013-03-15");
    echo date_format($date,"l");
    // echo date_format($date,"D");  // Output: Fri
    ?>
--------------------------------------------------------------------

0 Comments