Casting data types in custom fileds

alexm1
New Member

Hi all !

I’m quite new on Looker and slowly getting a grasp on how it works.

I’m trying to get a custom field which is an operation on a datetime (to which I’d add 18 hours, nothing crazy) in a string format. So basically I’m trying to cast this new datetime as a string.

Any thoughts? I haven’t seen a data casting function yet.

Thank you very much!

0 2 11.9K
2 REPLIES 2

Hi Alex,

When you say custom field, are you doing this operation in SQL in LookML files, or through the explore? Depending on where and what “language” you are trying to use, there should be functions for adding time intervals to a date, and then casting to a string.

MySQL example in LookML:
SELECT CAST(DATE_ADD(created_at, INTERVAL 18 HOUR) AS CHAR) FROM demo_db.orders

Looker Table Calculations Example:
to_string(add_hours(18, ${orders.created_time}))

These might help out, if not, feel free to come on chat and we can take a closer look!

Noah

Ana1
New Member

What if you need to cast as decimal for a number, what would you use in the looker table calculation?

Top Labels in this Space