Converting dates with PHP for DATETIME in SQL

前端 未结 4 840
旧巷少年郎
旧巷少年郎 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 08:10

    Two of several possible ways:

    1. Convert in code and then pass the converted value to mysql: $mysqldate = date( 'Y-m-d H:i:s', $phpdate );
    2. Let mysql do the work by using its built-in functions: $query = "UPDATE table SET datetimefield = FROM_UNIXTIME($phpdate) ...";

提交回复
热议问题