reformatting MySQL date (yyyy-mm-dd)

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

reformatting MySQL date (yyyy-mm-dd)

 
0
  #1
Jan 6th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

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

 
0
  #2
Jan 6th, 2007
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

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

 
0
  #3
Jan 6th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

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

 
0
  #4
Jan 6th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

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

 
0
  #5
Jan 6th, 2007
Or in php:

[php]
echo date('Y m d',strtotime($mysqldate));
[/php]
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

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

 
0
  #6
Jan 6th, 2007
Originally Posted by php_daemon View Post
Or in php:

[php]
echo date('Y m d',strtotime($mysqldate));
[/php]
Where is this pulling the date from?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

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

 
0
  #7
Jan 6th, 2007
Originally Posted by nathanpacker View Post
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

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

 
0
  #8
Jan 6th, 2007
Originally Posted by php_daemon View Post
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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

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

 
0
  #9
Jan 7th, 2007
Originally Posted by nathanpacker View Post
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

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

 
0
  #10
Jan 7th, 2007
Originally Posted by php_daemon View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC