When using the following
echo date('D',strtotime("2013-06-16T06:00:00-07:00"));
echo date('D',strtotime("2013-06-16T18:00:00-07:00"));
First it returns Sun
and the Second returns Mon
. I'm not really sure why or how to correct! The Date:"2013-06-16T06:00:00-07:00"
is data I'm retrieving from a XML file. The timestamp
has the correction for UTC
at the end not sure if this is generating the error.
Thanks for any help.
To get expected results you should consider using DateTime()
:
<?php
echo date('D',strtotime("2013-06-16T06:00:00-07:00")) . "
";
echo date('D',strtotime("2013-06-16T18:00:00-07:00")) . "
";;
$dt1 = new DateTime("2013-06-16T06:00:00-07:00");
$dt2 = new DateTime("2013-06-16T18:00:00-07:00");
echo $dt1->format('D') . "
";
echo $dt2->format('D') . "
";
Output
Sun
Mon
Sun
Sun
This is because The Date represents the time is in time zone specified in date.timezone
settings. So the timezone -07:00
is parsed and converted back to date.timezone
timezone.
To understand the idea just add e
in the date string
echo date('D e',strtotime("2013-06-16T06:00:00-07:00"));
echo date('D e',strtotime("2013-06-16T18:00:00-07:00"));
See example.
Its better you use DateTime(). It does not have such limitation.