0

I have this string I'm getting from the GUI: 09/22/2012 (mm/dd/yyyy).

I want to format it to:

date("Y-m-d");  //(the MySQL DATE format )

What should be the right PHP date function parameters to do so?

2
  • What do you mean by what shell the php ??? Commented Sep 22, 2012 at 20:14
  • @Baba I think he means "What should be the right parameters for the php date function" ("shell" is probably a typo for "shall"). Commented Sep 22, 2012 at 20:24

2 Answers 2

1

You can try

$date = DateTime::createFromFormat("m/d/Y", "09/22/2012");
echo $date->format("Y-m-d");

Output

2012-09-22
Sign up to request clarification or add additional context in comments.

1 Comment

This solution is better than the other one given.
1

You can also do the following to get the MySQL date format.

echo date('Y-m-d', strtotime('09/22/2012'));
// Output: 2012-09-22

Hope that helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.