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

前端 未结 10 1764
忘了有多久
忘了有多久 2020-12-14 18:03

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

相关标签:
10条回答
  • 2020-12-14 18:55

    I will suggest to use strtotime() function and then date(). By this you can convert any format of date.

    $unix_time_stamp = strtotime($mm_dd_yyyy);
    $yyyy_mm_dd = date(Y/m/d,$unix_timestamp);
    
    0 讨论(0)
  • 2020-12-14 18:55

    assign the date values to variable $d

    $dob denotes the date which you wish to convert

    $d= date('Y-m-d',strtotime ($dob) );
    
    0 讨论(0)
  • 2020-12-14 18:59
    $date = "07/12/2010";
    $your_date = date("Y-m-d", strtotime($date));
    

    I hope my answer is useful :)

    0 讨论(0)
  • 2020-12-14 18:59

    Alternatively you can do this without using the explode:

    $date = "12/25/2010";
    $mysql_date = date('Y-m-d', strtotime($date));
    

    You can now use $mysql_date to insert into your database.

    0 讨论(0)
提交回复
热议问题