I have a dates in mySQL stored in format 2012-09-16 as DATE format and I want to output and convert the date into the format date("l F jS")
.
I am using a while loop to query my table which SELECTS the date:
while($rowWeek=mysql_fetch_assoc($resultWeek)){
echo date("l F jS", $rowWeek[dt]);
}
The code above outputs: Wednesday December 31st
. For each and every day which tells me that date()
doesn't like the format being used from $rowWeek[dt]
when it should loop through 7 days of the current week.
echo $rowWeek[dt];
outputs the correct dates:
2012-09-16
2012-09-17
2012-09-18
2012-09-19
2012-09-20
2012-09-21
2012-09-22
How do I convert the SELECTED date format of 2012-09-16 and convert it to the more pleasant format of date("l F jS")
?
use strtotime()
:
echo date("l F jS", strtotime($rowWeek['dt']));
If you want to do the formatting in MySQL, you can do this:
SELECT dateformat("%W %M %D", mydate)
Just FYI, I'll get more value if you find this answer helpful than if I earn any points for it. What am I going to do, put my SO score on my resume??
Good luck.