Converting dates with PHP for DATETIME in SQL

前端 未结 4 841
旧巷少年郎
旧巷少年郎 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:45

    You can use the strtotime and date to rework the format.

    $new_date = date( "Y-m-d H:i:s", strtotime( $old_date ) );
    

    What this does is take your old date (dd/mm/yyyy hh:mm:ss), converts it to a unix timestamp that can then be used with the php date function to format the date to the desired format.

提交回复
热议问题