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

前端 未结 10 1762
忘了有多久
忘了有多久 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:38

    We need more information?

    1) What script is inserting into database? I am assuming PHP

    2) Also we need to know how you are storing the date and in what format?

    My solution would be:

    $dates = preg_split('/\//',$_POST['date']);
    
    $month = $dates[0];
    $day = $dates[1];
    $year = $dates[2];
    
    $finalDate = $year.'-'.$month.'-'.$day;
    

提交回复
热议问题