Convert date to month name & year

前端 未结 4 1757
一个人的身影
一个人的身影 2020-12-16 18:29

I am trying to convert a date to month name and year.

$date = \'2017-07-00\';
$date = date(\'m/y\', strtotime($date));
echo DATE_FORMAT($date, \'%M %Y\');


        
相关标签:
4条回答
  • 2020-12-16 19:11

    You can use this

    echo date('F,Y',strtotime($date));
    
    0 讨论(0)
  • 2020-12-16 19:13

    You are not using correct parameters, use F for moth and Y for year

    Full code:

    $date = '2017-07-00';
    $date = date('F, Y ', strtotime($date));
    echo $date;
    
    0 讨论(0)
  • 2020-12-16 19:18

    Try This.

    $date = '2017-07-01';
    $date = date('F, Y', strtotime($date));
    
    echo $date;
    
    0 讨论(0)
  • 2020-12-16 19:32

    No Need of DATE_FORMAT() function.

    Example-1: If 00 used in day. Then, output will be June, 2017

    <?php
    $date = '2017-07-00';
    echo date('F, Y', strtotime($date)); //June, 2017
    ?>
    

    Example-2: If 01 or valid day used in day. Then, output will be July, 2017

    <?php
    $date = '2017-07-01';
    echo date('F, Y', strtotime($date)); //July, 2017
    ?>
    
    0 讨论(0)
提交回复
热议问题