Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

php - Convert date to month name & year

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');

I am expecting output like

July, 2017

Here is error i am getting

Warning: date_format() expects parameter 1 to be DateTimeInterface, string given
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...