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.
This looks like your data isnāt always the same, meaning this error shows a value without the seconds, so do you have them all in the same format? if you have multiple formats you may need to use CASE with SAFE.PARSE_TIMESTAMP IS NULL
One last question on this thread and I am not sure it is relevant or not
In Qlik Sense, date or timestamp stores in numeric form in backend as 4993.32344 if timestamp and 4993 as date and we convert this number to any date as required format.
In Looker, how does raw or backend format of date stored? for example if I converted the string to timestamp then how actually it is stored?
Hereās the reference for the format elements (link above). You might have to adjust based on this, but as Dawid said, it looks like not all of the data is in the same format. Using the prefix āsafe.ā before the parse_timestamp function should return nulls whenever the function fails to parse the string because it is in a different format.
safe.parse_timestamp('%Y%m%d%H%M%S',cast(your_column as string))
Anyway, it looks like you got it working!
Regarding your storing question⦠If Iām not mistaken, Looker does not store any values in their backend. They simply run queries against your database based on the LookML youāve written (LookML generates SQL, it doesnāt actually store stuff) and return the results, so your database dialect will determine how things are stored and parsed. In this case, dates or timestamps are stored precisely as date or timestamp datatypes. BigQuery has a lot of great documentation, so you should be able to clear any doubts using that.
Thanks @jbendinger-1633 for such great information. Actually my two tables have common field a timestamp which has format: %Y%m%d%H%M.
I want to apply a join between those such tables. What is the best way here to apply the join? should I apply the join on raw value whose format is %Y%m%d%H%M%S or convert it to another best format where join never fails?
If both your tables are storing the information in the same datatype and format, Iād recommend just joining on the raw field. The reason for it is that the query will take a bit longer to run if you apply the parsing, because it will have to parse every record in each table and then compare those two records and join, whereas without parsing it would just evaluate if two numbers are equal without adding the extra step of parsing (I think you mentioned youāre storing them in float64 datatype).
Anyway, not a critical difference. However, if your columns are NOT storing the values exactly the same, I would recommend casting them to the same standard and then joining on them. Iād also say give both approaches a try and then compare results. But again, all this is very dependent on your data and the uniformity of it.
Just as a quick example, if you had value_table_1 = 20210101000000 (Jan 1st 2021 at 00:00:00) and value_table_2 = 20210101000000 (same as before), joining on those two would evaluate to true because both numbers are exactly the same, therefore producing a good join. However, if you had something like value_table_1 = 202111000000 (Jan 1st 2021 but dropping the 0 from the month and day) and then value_table_2 = 20210101000000 (same as previous example, where months and days do have zeroes), you might have to cast them both to the same timestamp format using the format elements to produce 2 timestamps that look the same, because value_table_1 (202111000000) is different than value_table_2 (20210101000000). I hope what Iām saying makes sense!
Hi,
I have got a similar requirement but the parse_date function is not giving me the desired output.
I have a field in the table which is of data type string and I need to convert to date. The values are as 202203,202204 and so on. (YYYYMM). I need to convert this value into Month/Mon - Year.
So the desired output is : March 2022, April 2022. Any suggestions, please?