I have dates in a database table in the form of yxxx-mx-dx, which I want to display as Mxxxx dx, yxxx.
I'd like to have something like:
date('F, j, Y', mktime(0, 0, 0, Mx, Dx, Yxxx));
do any of you have any idea how to convert yxxx-mx-dx into array(Mx, Dx, Yxxx)?
Please help!
Thanks.
Convert date format.
Moderator: General Moderators
-
spider.nick
- Forum Commoner
- Posts: 72
- Joined: Wed Jul 15, 2009 12:22 pm
- Location: Overland Park, KS
Re: Convert date format.
http://www.php.net/listgth759k wrote:I have dates in a database table in the form of yxxx-mx-dx, which I want to display as Mxxxx dx, yxxx.
I'd like to have something like:
date('F, j, Y', mktime(0, 0, 0, Mx, Dx, Yxxx));
do any of you have any idea how to convert yxxx-mx-dx into array(Mx, Dx, Yxxx)?
Please help!
Thanks.
http://www.php.net/explode
Code: Select all
list( $year, $month, $day ) = explode( '-', $date );Nick
Re: Convert date format.
Is the column of type 'date' in the database? If so, you can do this all in MySQL:
[sql]SELECT CONCAT(MONTHNAME(`yourDateField`),' ',DAYOFMONTH(`yourDateField`),', ',YEAR(`yourDateField`)) AS 'formattedDate'FROM `yourTable`[/sql]
[sql]SELECT CONCAT(MONTHNAME(`yourDateField`),' ',DAYOFMONTH(`yourDateField`),', ',YEAR(`yourDateField`)) AS 'formattedDate'FROM `yourTable`[/sql]
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Convert date format.
For that matter,pickle wrote:[sql]SELECT CONCAT(MONTHNAME(`yourDateField`),' ',DAYOFMONTH(`yourDateField`),', ',YEAR(`yourDateField`)) AS 'formattedDate'FROM `yourTable`[/sql]
Code: Select all
SELECT DATE_FORMAT(`yourDateField`, "%M %e, %Y") AS `formattedDate`...