Webmaster Help bookmark Demon
|
Welcome, Guest. Please login or register.
Did you miss your activation email?
Nov 21, 2008, 04:09:57 AM

Login with username, password and session length

When I'm inspired, I get excited because I can't wait to see what I'll come up with next.


- Dolly Parton

Welcome Guest - Register or Login Now to remove these advertisments


Registration is completely free and only takes a few minutes to signup !

|-   Entrepreneur Forum > Webmasters - Discuss Making Money Online > Website Design and Maintenance > Programming
+   How to convert mySQL datetime to normal date string in PHP?
0 Members and 6 Guests are viewing this topic.
Pages: [1] Reply to Thread
Author Topic: How to convert mySQL datetime to normal date string in PHP?  (Read 220 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?
Online~Dave~
Administrator
~Dave~ is a jewel in the rough~Dave~ is a jewel in the rough~Dave~ is a jewel in the rough~Dave~ is a jewel in the rough
Joined: Jan 2006
Posts: 6175


Avatar of code4gol

Go Phillies !!

View ~Dave~\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 : Insights Marketing With Google Insights for Search

Pages: [1] Reply to Thread


Code4Gold Affiliate Entrepreneur Moneymaker Forum © 2006-2008 Resdaz Media LLC - All Rights Reserved

Forum Software Powered by SMF - © 2001-2008, Lewis Media. All Rights Reserved.