开发者

mysql datetime YYYY-MM-DDTHH:MM:SS.SSSZ covert it to mysql ORDERBY

开发者 https://www.devze.com 2023-03-28 04:09 出处:网络
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 neith

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消