Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert MM/DD/YYYY to YYYY-MM-DD?

Tags:

I have a jquery calendar that sets the input value to MM/DD/YYYY

How would I convert it so that my database column (date) can accept it correctly?

EDIT

Gordon was right - his link pointed me to this answer

$mysql_date = date('Y-m-d H:i:s', strtotime($user_date)); 
like image 496
st4ck0v3rfl0w Avatar asked Jul 20 '10 08:07

st4ck0v3rfl0w


People also ask

How do I change the format of dd mm yyyy to dd mm yyyy?

First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.

How do I insert date in YYYY MM DD in Excel?

Select the cells you want to format. Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.

How do you convert MM DD to YYYY month?

Two extract the value for Month, first note that we have to cut the first four digits off so that yyyymmdd becomes mmdd. Then, dividing mmdd by 100 yields mm. This is done with MOD(Number,10000)/100, where MOD(Number,10000) retrieves mmdd and this result is divided by 100 yielding Month.

How do I change date from DMY to MDY?

Go to Format Cells > Custom Enter mm/dd/yyyy in the available space. Or you can use : Select a blank cell next to your date, for instance.


2 Answers

$date = "07/12/2010"; $your_date = date("Y-m-d", strtotime($date)); 

I hope my answer is useful :)

like image 182
Dae KIM Avatar answered Sep 21 '22 19:09

Dae KIM


You want to do this in PHP, right?

  1. Use Explode

    $christmas = "12/25/2010"; $parts = explode('/',$christmas); $yyyy_mm_dd = $parts[2] . '-' . $parts[0] . '-' . $parts[1] 
  2. Use strptime to parse it to a timestamp and then strftime to format it the way you want it.

like image 38
Alex Avatar answered Sep 25 '22 19:09

Alex