I am a bigquery newbie
we have a table that stores the output from time.time() as float. For example
1671057937.23425
1670884516.891432
How can I select these values such that they are formated/displayed as date and time stamp.
I have tried casting to int64, using various date/time functions like DATE_FROM_UNIX_DATE and TIMESTAMP_MICROS
Any suggestions would be greatly appreciated
CodePudding user response:
In Python, the time() function returns the number of seconds passed since epoch - so you can use below simple approach
select timestamp_micros(cast(1670884516.891432 * 1000000 as int64))
CodePudding user response:
to convert back to readable date time with python:
import datetime
stamp = "1670884516.891432"
readable = datetime.datetime.fromtimestamp(float(stamp))
print(readable)
result:
2022-12-13 01:35:16.891432
Please, formulate the question more clearly.
What do you mean with your words:
How can I select these values ...
Do you mean to select with SQL query? Then
SELECT convert(varchar, CURRENT_TIMESTAMP,21) ;