Search code examples
python-3.xstringgoogle-bigquerystring-formatting

How to get only the timestamp without the time zone as a string in Big Query?


I want to cast the current_timestamp in Big Query to a string but it add +00 which stand for UTC as the time zone to the string. I only want the timestamp without the zone i.e. without +00. How can I get that?

This is what I'm doing:


select STRING(CURRENT_TIMESTAMP()) as now

The result:

    
2022-11-29 10:56:12.793309+00

I want:

2022-11-29 10:56:12.793309

Solution

  • Consider more formal way below.

    SELECT FORMAT_TIMESTAMP('%F %T.%E*S', CURRENT_TIMESTAMP()) as now
    
    • %F - The date in the format %Y-%m-%d.
    • %T - The time in the format %H:%M:%S.
    • %E*S - Seconds with full fractional precision (a literal '*').