For most of the data sets in a data analytics, DATE function is the key field in the data set. One date field included many meaningful data within the Date like, Days, Months, Years and Time. However, in some visualization we need separated characteristics of DATE field. In this situation we need date function in Tableau to manipulate date filed and get the desire output in table or visualization.
In this tutorial of DATE function in Tableau, you will learn all DATE functions which is needed to understand:
DATE functions in Tableau:
DATENAME
Definition: Datename function in Tableau return the string value for date_part from Date field, example, year, month.
Syntax: DATENAME(date_part, date, [start_of_week])
Return Output: As String
Example: DATENAME (‘month’, #2020-04-23#), and output will be “April”
DATEPARSE
Definition: DATEPARSE() function is used to convert a given string date field into a date or datetime value.
Syntax: DATEPARSE (date_format, date_string)
Return Output: As Date
Example: DATEPARSE (‘yyyy-MM-dd’, “2020-03-15”), and the output of this example will be #March 15, 2020#
DATEPART
Definition: This date function in Tableau return the date_part of the given date, like, month, day, week, year.
Syntax: DATEPART(date_part, date, [start_of_week])
Return Output: As integer
Example: DATEPART (‘year’, #2021-05-21#), and the output will be = 2021
DATEDIFF
Definition: DATEDIFF date function calculate the difference between two given date expression <date_1> and <date_2>
Syntax: DATEDIFF(date_part, date_1, date_2, [start_of_week])
Return Output: As Integer
Example: DATEDIFF(‘month’, #1/25/2020#, #4/25/2020#) , and output for this date function will be = 3, which is 3 month between these two date
DATEADD
Definition: The DATEADD in Tableau is used to add a specific amount of time to a date or datetime value.
Syntax: DATEADD (date_part, interval, date)
Return Output: As Date
Example: DATEADD (‘day’, 10, #3/20/2021#) , and output for this date function will be = March 20, 2021, As it is added 10 more days in the date.
DATETRUNC
Definition: DATETRUNC date function is used to truncate a date (shorten the duration) to a specific level of granularity. Like year, quarter, month, week, day, hour, minute, or second.
Syntax: DATETRUNC (date_part, date, [start_of_week])
Return Output: As Date
Example: DATETRUNC (‘hour’, #2021-02-23 10:40:00#) , and this date function will give you the beginning of hour, i.e 10:00:00, so output will be #2021-02-23 10:00:00#.