简体   繁体   中英

How to format a timestamp to string with fractional seconds in BigQuery?

This is a pretty straightforward question that I cannot seem to find the answer to.

I am working in BigQuery and have a timestamp:

2022-01-02 13:00:01.5849

I want to convert this to a string with all dashes, colons and spaces removed. End result should look like this:

202201021300015849

I am able to get everything before the decimal formatted fine but can't seem to figure out how to grab the fractional seconds.

This is what I have working so far:

SELECT FORMAT_DATE('%Y%m%d%H%M%S', timestamp '2022-01-02 13:00:01.5849')

The output of this is:

20220102130001

Obviously this is missing the.5849 fractional seconds

Thank you

Use below

SELECT REPLACE(FORMAT_DATE('%Y%m%d%H%M%E*S', timestamp '2022-01-02 13:00:01.5849'), '.', '')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM