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

2022-08-30 17:21:47

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));

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

I hope my answer is useful :)


答案 2

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 to parse it to a timestamp and then to format it the way you want it.strptimestrftime


推荐