0

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?

4
Contributors
10
Replies
15
Views
10 Years
Discussion Span
Last Post by kblenman
0

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?

0

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

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

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

Thanks.

0

Or in php:

echo date('Y m d',strtotime($mysqldate));

Where is this pulling the date from?

0

Where is this pulling the date from?

This is assuming you've a date already fetched from a database to $mysqldate.

0

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!

0

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.

0

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.

0

That's awesome. So much easier than the way I was doing it. Thanks.

Are you able to post the final code from fetch to echo? (assuming successful implementation)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.