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

Time:10-21

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

CodePudding user response:

Use below

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