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?

Recommended Answers

All 10 Replies

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?

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.

Or in php:

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

Or in php:

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

Where is this pulling the date from?

Where is this pulling the date from?

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

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!

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.

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.

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.