Tableau Date Functions

Tableau provides various Date Functions such as Year, Month, Day, makedate, maketime, datediff, datepart, dateadd, datename, datetrunc, now, today, etc. In this article, we will show you how to use Tableau Date Functions with examples.

To demonstrate these Tableau Date functions, we are going to use the below shown data. As you can see, there are 15 records in this table.

Tableau Date Functions 1

Tableau Date Functions

The following set of examples will show you the list of Tableau Date Functions

Tableau Year Function

The Tableau YEAR function is used to return Year from the given date. The syntax of this Tableau YEAR:

YEAR(Date)

To demonstrate the date functions in Tableau, we have to use Calculated Fields. To create a calculated field, navigate to Analysis Tab, and select the Create Calculated Field… option.

Tableau Date Functions 2

Once you click on the Create Calculated Field, the following window will open. Here, we renamed the default calculation name as Year.

As you can see from the below screenshot, while I was typing, the calculation window is showing the suggestions.

Tableau Date Functions 3

For the demo purpose, we will return the Years from HireDate

YEAR([HireDate])
Tableau Year Function 4

Let me add this calculated field to the table (by dragging a field to Rows Shelf) that we created earlier. Please refer Create Table Report article to understand the steps involved in creating a table

Tableau Year Function 5

Because it is a measure, sometimes it may not show properly. If this is the case, click on the Year and change it from Measure to Dimension. Next, change the values from Continuous to Discrete.

Tableau Year Function 6

Tableau MONTH Function

The Tableau Month function is used to return the Month number from a given date. The syntax of this Tableau Month Function is

MONTH(Date)

Let me create a calculated field to return the Month number from Hiredate

MONTH([HireDate])
Tableau Month Function 7

Let me add this Tableau Month Number field to the Rows shelf

Tableau Month Function 8

Tableau DAY Function

The Tableau DAY function is used to extract or return Day number from a given date. The syntax of this Tableau DAY Function is:

DAY(Date)

Let me create a Tableau Day field to return Day number from HireDate

DAY([HireDate])
Tableau Day Function 9

Next, we added the Tableau day field to the Row Shelf

Tableau Day Function 10

Tableau NOW Function

The Tableau NOW function is used to return today’s date and time. The syntax of this Tableau NOW Function is:

NOW()

Let me create one calculated field for NOW function to return today’s date and time

NOW()
Tableau NOW function 11

From the below screenshot, you can see today’s date and time

Tableau NOW function 12

Tableau Today Function

The Tableau Today function is used to return today’s date. The syntax of this Tableau Today Function is:

TODAY()

Let’s create a field to return today’s’ date

Tableau Today function 13

From the following screenshot, you can see today’s date

Tableau Today function 14

Tableau MakeDate Function

The Tableau MakeDate function is used to return date from the year, month, and day. The syntax of this Tableau MakeDate Function is:

MAKEDATE(year, month, day)

Let’s create another calculated field to return date from the specified year, month, and day. As you can see, we used Year(), MONTH(), and DAY() function to extract corresponding value.

MAKEDATE(YEAR([HireDate]), MONTH([HireDate]), DAY([HireDate]))
Tableau MakeDate Function 15

You can see the Tableau MakeDate Function result

Tableau MakeDate Function 16

Tableau MakeTime Function

The Tableau MakeTime function is used to return time from an hour, minute, and seconds. The syntax of this Tableau MakeTime Function is:

MAKETIME(hour, minute, second)

Let me create a calculated field to return time from hour, minute, and seconds. As you can see, we are giving static values. However, you can use Datepart to extract hours minutes and seconds from date and time.

MAKETIME(14, 22, 59)
Tableau MakeTime Function 17

Now, you can see the MakeTime Function result. Remember, 30 Dec, 99 is the default date generated by tableau

Tableau MakeTime Function 18

Tableau MakeDateTime Function

The Tableau MakeDateTime function is used to return date and time from Date, Time. The syntax of this Tableau MakeDateTime Function is:

MAKEDATETIME(Date, Time)

As you can see, we are using the previously created calculated fields as arguments. MakeDt will return Date from HireDate, and MakeTime will return static time value.

MAKEDATETIME([MakeDt], [MakeTime])
Tableau MakeDateTime Function 19

Let me add this MakeDateTime function field to table

Tableau MakeDateTime Function 20

Tableau ISDATE Function

The Tableau IsDate function is used to check whether the given string is a date or not. It returns either True or False. The syntax of this Tableau IsDate Function is:

ISDATE(string)

Let me use this function on the string Hire Date column. As you can see, this is a string column

ISDATE([StringHireDate])
Tableau ISDATE Function 21

You can see the result of this IsDate function

Tableau ISDATE Function 22

Tableau DATEDIFF Function

The Tableau DATEDIFF function is used to return the date difference between the start date and end date. Use the first argument to specify the difference term.

This Tableau datediff function accepts YEAR, MONTH, DAY etc. For example, if you select YEAR, Tableau DateDiff function will return the number of years between a start date and end date.

The syntax of this Tableau DATEDIFF is:

DATEDIFF(Difference_term, Start_Date, End_Date)

Let me check the difference between HireDate and Today in years using datediff in tableau.

DATEDIFF('year', [HireDate], NOW())
Tableau DATEDIFF function 23

From the below screenshot, you can see the total number of years between HireDate and Today

Tableau DATEDIFF function 24

Let me change the difference term to MONTH in Tableau datediff, and click the Apply button.

Now you can see the difference between those dates in Months

Tableau DATEDIFF function 25

Tableau DATEADD Function

The Tableau DATEADD function is used to add user-specified intervals to an actual date. Use the first argument to define the date part term, and the second arg to specify the interval.

This Tableau DATEADD function accepts YEAR, MONTH, DAY, etc. For example, if you select Month as the first argument and interval as 6, then Tableau Dateadd function will add six months to the existing date.

The syntax of the Tableau DATEADD is:

DATEADD(Date_part, interval, Date)

The below statement will add 5 years to HireDate.

DATEADD('year', 5, [HireDate])
Tableau DATEADD function 26

This time we will use, month as the date part in Tableau DATEADD. the below statement adds 6 months to HireDate.

DATEADD('month', 6, [HireDate])
Tableau DATEADD function 27

Tableau DATEPART Function

The Tableau DATEPART function is used to extract or return part of a date. Use the first arg to specify the date part.

This Tableau DatePart function accepts YEAR, MONTH, DAY etc. For example, if you select Month as date part, then Tableau DatePart function will return a year from a given date.

The syntax of this Tableau DATEPART is:

DATEPART(Date_part, Date)

The following statement will extract the day number from HireDate.

DATEPART('day', [HireDate])
Tableau DATEPART function 28

This time we will use Hour as the datepart in Tableau. The Below statement will return Hour from HireDate

DATEPART('hour', [HireDate])
Tableau DATEPART function 29

Tableau DATENAME Function

The Tableau DATENAME function is used to return the date part name. Use the first argument to specify the date part, and it accepts YEAR, MONTH, DAY.

The syntax of the Tableau DATENAME is:

DATENAME(Date_part, Date)

The below statement will return the Month name from HireDate.

DATENAME('month', [HireDate])
Tableau Date Functions 30

This time we will use weekday as the date part in DateName. Below statement will return weekday name from HireDate

DATENAME('weekday', [HireDate])
Tableau Date Name 31

Tableau DATETRUNC Function

The Tableau DATETRUNC function is one of the Tableau date function. It is used to return the first day of the specified date part. Use the first argument to specify the date part, and this Tableau datetrunc function accepts YEAR, MONTH, DAY, etc.

The syntax of the Tableau DATETRUNC is:

DATETRUNC(Date_part, Date)

The below statement will return the Month starting date from HireDate.

DATETRUNC('month', [HireDate])
Tableau DateName Function 32

This time we will use a quarter as the date part in Tableau DATETRUNC function. Below statement will return the first day of the quarter that the date belongs to

DATETRUNC('quarter', [HireDate])
Tableau DateName Function 33