Internet Marketing Forum

Internet Marketing Forum


For Webmasters and Entrepreneurs
468x60 Russell Simmons
|
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2012, 07:01:33 PM

Login with username, password and session length

Success does not consist in never making blunders, but in never making the same one a second time.


- Josh Billings

|-   Internet Marketing Forum > Online Business Discussions > Website Design and Maintenance > Programming
+  

How to convert mySQL datetime to normal date string in PHP?

0 Members and 10 Guests are viewing this topic.
Pages: [1] Reply to Thread
Author Topic: How to convert mySQL datetime to normal date string in PHP?  (Read 8030 times)
Offlinegreenflassh
New Member
greenflassh is on a distinguished road
Joined: Oct 2008
Posts: 8


anonymous avatar

View greenflassh\s Profile
United States
notepad Oct 05, 2008, 07:26:49 PM #1
I'm trying to do things the right way and now I've been using the "datetime" datatype in my mysql tables where they contain dates and times when I used to use varchar.

The problem is this...

When I pull  a date from the db for html output, instead of the current display of 2008-10-05 19:13:37, my client wants it to show October 5, 2008, 7:28pm.

This was a no-brainer when I was just using string data... but now it's a headache

How can I easily convert an accurate datetime type to something like the above?

Can it be done?
OfflineCode4Gold
Administrator
Code4Gold is a jewel in the roughCode4Gold is a jewel in the roughCode4Gold is a jewel in the roughCode4Gold is a jewel in the rough
Joined: Jan 2006
Posts: 6215


Avatar of Code4Gold

Administrator

View Code4Gold\s ProfileWWW
Gender: MaleGemini United States
notepad Oct 06, 2008, 12:55:45 AM #2
You don't need to use PHP to format a datetime field. You can do it right in your SQL statement by using the DATE_FORMAT() function so you can just do something like this

SELECT DATE_FORMAT( your_date_field, '%M %e, %Y, %l:%i%p') as newdate FROM your_table;

newdate will be the date in the format you want

Here's more information on the  DATE_FORMAT() function

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format

Latest Blog Post : 8 Tips for Creating a Marketing Buzz

AWeber - Email Marketing Made Easy
Pages: [1] Reply to Thread


Code4Gold Internet Marketing Forum © 2006-2011 Resdaz Media LLC - All Rights Reserved
Forum Software Powered by SMF - © 2001-2008, Lewis Media. All Rights Reserved.