How to get year and month from a date - PHP

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

    $dateValue = '2012-01-05';
    $yeararray = explode("-", $dateValue);
    
    echo "Year : ". $yeararray[0];
    echo "Month : ". date( 'F', mktime(0, 0, 0, $yeararray[1]));
    

    Usiong explode() this can be done.

提交回复
热议问题