How to get year and month from a date - PHP

后端 未结 10 1373
一个人的身影
一个人的身影 2020-12-24 06:37

How to get year and month from a given date.

e.g. $dateValue = \'2012-01-05\';

From this date I need to get year as 2012

10条回答
  •  庸人自扰
    2020-12-24 07:26

    Using date() and strtotime() from the docs.

    $date = "2012-01-05";
    
    $year = date('Y', strtotime($date));
    
    $month = date('F', strtotime($date));
    
    echo $month
    

提交回复
热议问题