The date functions are useful for a variety of tasks, such as identifying the elapsed time between two events or a part of a date.
Many date functions in Tableau Public operate on dateparts. Dateparts are the small units of measurement of dates, such as a year, quarter, month, week, day, and the units of time, such as an hour, a minute, and a second. Writing date functions in Tableau Public is similar to writing date functions in ANSI SQL or Microsoft Excel with a big difference—dateparts need to be spelled out and enclosed in single quotation marks, which is a relatively simple design and use of punctuation for a programming language.
The most commonly performed analysis is the measurement of change over time, and the prevalence of date functions is high. Therefore, it is worth the time and effort to master them early on in your work with Tableau Public.
The date functions include the following functions:
DATENAME('month', #7/21/2015#) = "July"
.DATEPART('month', #7/21/2015#) = 7
.DATETRUNC('month, #7/21/2015#) = '7/1/2015'
.DAY(#7/21/2015#) = 21
.true
or false
).date
and datetime
of the current moment by using the time settings on your computer.In the following example, we will use the floods data to determine the number of years that have elapsed since the last major flood. Most of the countries have had many floods and not just one. Therefore, we used the maximum value of Date Began, which is the most recent date in the data set, and compared it with today's date.
We could have omitted the max from the Date Began, but for each country, Tableau Public would have then aggregated the elapsed time per country, and we really wanted to know how long it has been since the most recent flood, as shown in the following screenshot: