How to convert string to timestamp in looker

Hi team,

We have date string as 20210131120101(YYYYMMDDhhmmss) in table. We want to interpret this string into timestamp so looker can treat it as time stamp.

Then we want to extract date parts from 20210131120101:

2021: year

01: month

31: day

12:hour

01: minute

01:second

I have tried parse_timestamp function because my source database is bigquery but this is the error I am getting:

b71f06a1-3e1f-4e1c-9754-b8ce26f680bf.png

Thanks in advance

Thanks,

Rohit

Solved Solved
0 13 6,393
1 ACCEPTED SOLUTION

This function parsed the example you provided:

parse_timestamp('%Y%m%d%H%M%S',cast(20210131120101 as string))

To apply it to your column, you should use this and replace “your_column” with the column name that contains your timestamp:

parse_timestamp('%Y%m%d%H%M%S',cast(your_column as string))

The error you’re getting on that message refers to the second argument of the function (the column containing the timestamp) not being of string datatype, but float datatype. You should cast your float to a string first, just like in the example.

I hope this helps.

Warmly, 

View solution in original post

13 REPLIES 13
Top Labels in this Space
Top Solution Authors