Casting data types in custom fileds

  • 7 November 2018
  • 2 replies

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!

2 replies

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!


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