How to get year and month from a date - PHP

后端 未结 10 1401
一个人的身影
一个人的身影 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:37

    You can use this code:

    $dateValue = strtotime('2012-06-05');
    $year = date('Y',$dateValue);
    $monthName = date('F',$dateValue);
    $monthNo = date('m',$dateValue);
    printf("m=[%s], m=[%d], y=[%s]\n", $monthName, $monthNo, $year);
    

提交回复
热议问题