Date formatting for table calculation


(Dawid) #1


I would like to change the format of the date column from 2019-01-01 to 1 January 2019. Tried doing it using table calculation but I can’t see any formatting functions that would help me achieve it.

(Nicholas Wong) #2

At this time date formatting, color formatting, and hexadecimal conversion are not supported in Looker table calculation. However, if you’re doing it on a graph, you can use %d%B%Y as the data type. You can read more about it at

If you’re showing it in a table format, that wouldn’t work. So the next best option is to modify your LookML.

html: {{ rendered_value | date: “%d %B, %Y” }};;

Take a read at Easy date formatting with Liquid article where its written by Brecht Vermeire, who’s a Looker staff. :slight_smile: Hope this helps!

(Dawid) #3

It’s not really a chart. It’s a single value visualisation but in my opinion when single value vis type is offered you should be able to format it to a more human-readable output?

(Izzy) #4

Yup! Like @nicholaswongsg said, it’s totally possible to reformat them— I found the article written by Brecht that he mentioned, give it a read.

(Dawid) #5

I don’t want to do it in the LookML and building a new explore etc. - it’s just for one specific look, so I want to do it on “front-end” just as display format change

(Nicholas Wong) #6

Hey, I totally understand where you’re coming from! The next best question will be how can I hide the dimension while using it to create the dashboard. As Looker don’t have that feature (or at least yet), the only solution is to create a folder to hide it. (Although there have been lots of request for it…)

(Ian) #7

Can you not create a calculated column in the viz and concat the stripped date parts into the string format you wish

(Izzy) #8

That suggestion sounds spot on, if you only have one date field, then something like

concat(extract_days(${ascent.date_date}), " ",
                        if(extract_months(${ascent.date_date})=12,"December",null)))))))))))), " "

That’s assuming you only have the one date field being returned. If you use a dimension group and instead query one field for day, one field for year, and one field for month name (would get the same grouping), you won’t need that yucky nested if() statement and could just say

concat(${table.date_day_of_month}, " ",
  ${table.date_month_name}, " "

(Brecht Vermeire) #9

I’ve actually come across an even simpler way.

Calculate the diff_days between 1899-12-30 (blame spreadsheets) and your actual date.

For example:

diff_days(to_date("1899-12-30"), ${users.created_date})

Now you can use the Excel-like date formatting described here.

So for “1 January 2019”, use d mmmm yyyyy in your custom value format on the table calculation.

(Nicholas Wong) #10

This is amazing! Work like a charm. :smiley:

(Dawid) #11

Thanks I will try this…

Isn’t it counter-intuitive to have to use days difference to format a date? It’s quite simple task that a function like format_date would solve all the problems

(Dawid) #12

Why wouldn’t hh:mm:ss work here?


(Brecht Vermeire) #13

Looks like that’s the way Excel & Office do it for dates only.

You can however use this calculation for readable hours:

  to_date("1970-01-01 00:00:00"), 
  ${users.created_time}) / 86400

Basically changing it from a datetime to an epoch timestamp by calculating the seconds since 1970-01-01 and changing that to days by dividing by 86400.
Then in the custom format, you can use hh:mm:ss.

(Dawid) #14

In other words I have to create to different fields, then use those functions, then create another field that would concatenate the two?

(Izzy) #15

You could do it all in one larger nested table calculation as well if you only want 1 extra field in the explore to keep things tidy.