There are three types of time fields in MySQL:
Datetime,date and timestamp.
DateTime holds the data in YYYY-MM-DD HH:MM:SS format string;
Date is a string of yyyy-mm-dd in the form of only a month and a day;
The timestamp type has the same name as the timestamp type in PHP, but the two are basically different.
PHP is the type of Unix time signature that is followed by an integer, while in MySQL the timestamp field is changed with the record and a
Automatically updated to the Datetimp field of the time. After the mysql4.1 version of the timestamp format, the datetime format is basically consistent.
It is often necessary to convert the timestamp in both formats in PHP and mSQL. The conversion method summarizes:
The first method: Use the date () and strtotime () functions
$mysqltime =date (' y-m-d h:i:s ', $phptime);
$phptime =strtotime ($mysqldate);
The second method: Use the MySQL function transformation in the query statement:
Unix_timestamp (datetime=>php TIMESTAMP) and
From_unixtime (PHP timestamp=>datetime).
$sql = "Select Unix_timestamp (Datetimefield) from table WHERE ...";
$sql = "UPDATE table set Datetimefield=from_unixtime ($phptime) WHERE:";
The third Way: MySQL uses integer fields to save PHP's timestamp type.
This article is from the "Sheep" blog, please make sure to keep this source http://5934497.blog.51cto.com/5924497/1683518
PHP and MySQL timestamp interchange