Image AI-generated from [time, data, now, code] | Starryai

As the name suggests, Tableau's date functions are used to work with dates. For example, they can be used to modify existing dates, create new ones, and return values for specific dates. In this blog post, we'll overview some commonly used functions and provide an example of each.


TODAY() and NOW()

These functions return today's date and today's date and time, respectively.

Plain text
TODAY() // Returns 03/05/2022
NOW() // Returns 03/05/2022 12:08:22

YEAR(), MONTH(), and DAY()

These functions return the specified element of a date value.

Plain text
YEAR([date_field]) // Returns the year
MONTH([date_field]) // Returns the month
DAY([date_field]) // Returns the day

DATEPART() and DATENAME()

These functions also return specified elements of a date, either as an integer or a string, respectively.

Plain text
DATEPART('year', [date_field]) 
// Returns specified part of the date as an integer

DATENAME('year', [date_field])
// Returns specified part of the date as a string


DATEADD()

This function adds a specified length of time to a date value and returns the product.

Plain text
DATEADD('day', 20, [date_field]) 
// Returns dates 20 days after [date_field] values

DATEDIFF()

This function is used to calculate the time difference between two date fields, with the unit of time used to measure this difference specified as an argument.

Plain text
DATEDIFF('week', [date_start], [date_end])
// Returns the difference between two fields in weeks