milliseconds format to parse a datetime?

蓝咒 提交于 2020-05-09 17:14:51

问题


I need to parse a datetime contains milliseconds for matching the max value in a field containing this datetimes.

For example:

#standardSQL
SELECT PARSE_DATETIME('%Y-%m-%d %H:%M:%S.%u','2017-08-18 16:04:40.890') 

Any suggestions? Thanks in advance.

UPDATE: Convert to milliseconds, suddendly MAX().

#standardSQL
WITH Input AS (
  SELECT date
  FROM UNNEST([
    DATETIME '2017-08-18 16:04:40.890',
    DATETIME '2017-07-27 11:09:10.347',
    DATETIME '2017-08-22 13:17:34.727',
    DATETIME '2017-08-22 13:17:34.737']) AS date
)
SELECT
  MAX(CAST(date AS DATETIME))
FROM Input;

回答1:


below is for BigQuery Standard SQL

#standardSQL
SELECT PARSE_DATETIME('%Y-%m-%d %H:%M:%E*S','2017-08-18 16:04:40.890') 


来源:https://stackoverflow.com/questions/46238787/milliseconds-format-to-parse-a-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!