Basic Date Functions in Tableau

This blog post will break down all the different date functions in Tableau, and how and where to use them. Without further ado, let's get started!

DAY/WEEK/MONTH/QUARTER/YEAR

These functions do exactly what they say on the tin, and will break up your date field into whatever you specify, outputting just that value.

DATEADD/DIFF

We can think about DATEADD and DATEDIFF like an addition and subtraction tool for your date fields. With both, you can specify what part of the day you want to add/workout the difference from, and you can even use other fields to work this out instead of a static number.

DATENAME/PARSE/PART/TRUNC

These four functions are all about splitting up or transforming our date fields to become more suitable to our needs. All have varying use cases.

DATENAME will give you the name of the numerical value. For example, DATENAME('month', 09/11/2021) will return November.

DATEPARSE transforms the data type of your field from a string to a DateTime format, and so is extremely useful when cleaning up your data in a Tableau-friendly format.

DATEPART will return just the numerical value of the part of the date specified, so very similar to DATENAME, but returning an integer instead of a string. For example, DATEPART('month', 09/11/2021) will return 11.

DATETRUNC will shorten our date field to only show the part specified, essentially rounding up our dates to the nearest value. For example DATETRUNC('month', 09/11/2021), will round our date value to 01/11/2021.

And that's the basics! If you're new to date functions, go out there and see what you can create with them now at your disposal.

Author:
Carlo Sanzeri
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab