-1

Possible Duplicate:
Change date format (in DB or output) to dd/mm/yyyy - PHP MySQL
PHP - Convert to date format dd/mm/yyyy

mysql saves my date and times like this...

 2011-08-31 08:48:40 

And when I echo them from the database this is how they appear, how can I get them to a universal format like m/d/y...

Or does it not matter if the mysql row is not a DATE_TIME and just VARCHAR and insert it into the database how I want it??

Thanks...

16
  • date("m/d/y h:i:s", strtotime('2011-08-31 08:48:40')) Commented Sep 1, 2011 at 6:14
  • 3
    erm... what you have there is an universal format. m/d/y is a locale format... Commented Sep 1, 2011 at 6:15
  • Thank you... put it as an answer and I will mark it as correct :) Commented Sep 1, 2011 at 6:18
  • 1
    "Universal" as in "American"? Yeah... Commented Sep 1, 2011 at 6:23
  • 1
    @carl I just know how to use the search function. :P Commented Sep 1, 2011 at 6:36

2 Answers 2

3

Do it in PHP:

date("m/d/Y", strtotime('2011-08-31 08:48:40')); 

Or do it in MySQL:

SELECT DATE_FORMAT('2011-08-31 08:48:40','%m/%d/%Y') 

Of course you won't use hardcoded values in your code. You'll use the column name for MySQL or the retrieved column value, that's probably an element in an array, in PHP.

Sign up to request clarification or add additional context in comments.

Comments

0

This post is previously answered:

Convert to date format dd/mm/yyyy

Regards

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.