I need to store a specific time format in sql s开发者_JS百科o I can ORDER BY later . The format that I have is YYYY-MM-DDTHH:MM:SS.SSSZ (e.g., 2004-08-04T19:09:02.768Z) which doesn't seem to be neither unix time or mysql date format . I'm using PHP get the time from a webservice which provides it in this format .
strtotime
can parse that datetime string into a timestamp, which you can then format as desired.
$date = date('Y-m-d H:i:s', strtotime('2004-08-04T19:09:02.768Z'));
$sql = "INSERT INTO table (datecol) VALUES ('$date')";
First, convert the date (which looks to me like ISO 8601 format) to a PHP timestamp
$datetime = strtorime("2004-08-04T19:09:02.768Z");
Then the SQL date format is
date ("Y-m-d H:i:s", $datetime);
精彩评论