PARSE_DATETIME formatting with day of year

前端 未结 2 333
太阳男子
太阳男子 2021-01-29 04:30

Having an issue with the PARSE_DATETIME function in BigQuery used with the day of year (%j) formatting element. The function seems to ignore the day of year element.

Eg.

2条回答
  •  深忆病人
    2021-01-29 05:20

    I think that this is a bug that could be fixed! there is no logic in it working one way but not opposite!

    Meantime, you can use below to achieve goal

    #standardSQL
    CREATE TEMP FUNCTION PARSE_DATETIME_WITH_DAYS(x STRING) AS (
      DATETIME_ADD(PARSE_DATETIME('%Y%j', x), INTERVAL CAST(SUBSTR(x, -3) AS INT64) - 1 DAY)
    );
    SELECT PARSE_DATETIME_WITH_DAYS('2013243')  
    

    with result -

    Row f0_  
    1   2013-08-31T00:00:00  
    

提交回复
热议问题