Page 1 of 1

Convert date format.

Posted: Fri Jul 17, 2009 9:06 am
by gth759k
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.

Re: Convert date format.

Posted: Fri Jul 17, 2009 9:40 am
by spider.nick
gth759k 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/list
http://www.php.net/explode

Code: Select all

list( $year, $month, $day ) = explode( '-', $date );
Hope that helps!

Nick

Re: Convert date format.

Posted: Fri Jul 17, 2009 10:52 am
by pickle
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]

Re: Convert date format.

Posted: Fri Jul 17, 2009 12:39 pm
by requinix
pickle wrote:[sql]SELECT  CONCAT(MONTHNAME(`yourDateField`),' ',DAYOFMONTH(`yourDateField`),', ',YEAR(`yourDateField`)) AS 'formattedDate'FROM  `yourTable`[/sql]
For that matter,

Code: Select all

SELECT DATE_FORMAT(`yourDateField`, "%M %e, %Y") AS `formattedDate`...