Converting dates with PHP for DATETIME in SQL

前端 未结 4 842
旧巷少年郎
旧巷少年郎 2020-12-06 07:32

I have a forum in PHP which takes a date like in the form dd/mm/yyyy hh:mm:ss. However, I need to insert it for SQL as a DATETIME in the format as yyyy-m

4条回答
  •  醉酒成梦
    2020-12-06 07:53

    if you have datetime avaialable from a from like above format then u just need to use following function.

    function localToMysql($dateTime){
      $date_chunks = explode('/', $dateTime);
        $time_chunks = explode(' ', $date_chunks[2]);
        $final_format = $time_chunks[0] . "-" . $date_chunks[1] . "-" . $date_chunks[0] . " " . $time_chunks[1];
    

    return $final_format; }

提交回复
热议问题