944,066 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 12380
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 6th, 2007
0

reformatting MySQL date (yyyy-mm-dd)

Expand Post »
Hey, I need help getting that ugly yyyy-mm-dd format to change to something prettier. I would prefer being able to output it in the form like January 01, 2007. Something easy to read for the average user. I can leave it stored in yyyy-mm-dd in my database, but in my output I'd like to reformat it.

Any pointers?
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jan 6th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jan 6th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Thanks, I have used that function before, but it seems that I can only format the current system time with that function. How can I take a previous date/time recorded in a database and use this fuction with it?
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jan 6th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Well, after some searching around, I found this bit of code that can be used in the SELECT function that works for me:

[PHP]
SELECT date_format(my_date, '%M %e, %Y') as date, FROM my_table

[/PHP]

It then stores the date in the format I want in the variable called "date".

Thanks.
Last edited by nathanpacker; Jan 6th, 2007 at 8:46 am.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jan 6th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Or in php:

[php]
echo date('Y m d',strtotime($mysqldate));
[/php]
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Jan 6th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Click to Expand / Collapse  Quote originally posted by php_daemon ...
Or in php:

[php]
echo date('Y m d',strtotime($mysqldate));
[/php]
Where is this pulling the date from?
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jan 6th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Where is this pulling the date from?
This is assuming you've a date already fetched from a database to $mysqldate.
Last edited by php_daemon; Jan 6th, 2007 at 7:35 pm.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Jan 6th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Click to Expand / Collapse  Quote originally posted by php_daemon ...
This is assuming you've a date already fetched from a database to $mysqldate.
Ah, so I can pull the date from the database, and put it in a variable, say $mysqldate, and then use that to format it? That's even easier! Thanks!
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jan 7th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Ah, so I can pull the date from the database, and put it in a variable, say $mysqldate, and then use that to format it? That's even easier! Thanks!
Yes, exactly. Although there's no difference as far as the performance is concerned, personally I prefer to leave the data formatting to php rather than mysql, simply for the sake of responsibility separation.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Jan 7th, 2007
0

Re: reformatting MySQL date (yyyy-mm-dd)

Click to Expand / Collapse  Quote originally posted by php_daemon ...
Yes, exactly. Although there's no difference as far as the performance is concerned, personally I prefer to leave the data formatting to php rather than mysql, simply for the sake of responsibility separation.
That's awesome. So much easier than the way I was doing it. Thanks.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How do i display records of an item into textbox based on drop down list
Next Thread in PHP Forum Timeline: php and dom? (dommitall).





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC