I have a bit of PHP code:
$exd = date_create('01 Dec, 2015');
$exd = date_format($exd, 'Y-m-d');
echo $exd;
Which is used for formatting the date. The expected output would be 2015-12-01
but it returns 2016-12-01
. What am i missing?
I have a bit of PHP code:
$exd = date_create('01 Dec, 2015');
$exd = date_format($exd, 'Y-m-d');
echo $exd;
Which is used for formatting the date. The expected output would be 2015-12-01
but it returns 2016-12-01
. What am i missing?
Use
createFromFormat
method first, provide the input format:i got the solution of your bug that is date_format(datae_variable,date_format);
It can be a date function call simply. Use stringtotime for exact/precise date/time value
When you run this code the out put will show
this is because of the comma in the string which terminates the date string in the compiler. If you specify exactly the timezone (like
$timezone = 'America/New_York
) . parameter you can show precise time as well.The
date_create()
function accepts only the parameter link, This function is also and alias function ofDateTime::__construct()
check the function
date_create_from_format()
its also a alias function of DateTime::createFromFormat(). Refer link