# 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

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.

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.

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

`YEAR([HireDate])`

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

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 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])`

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

### 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])`

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

### 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()`

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

### Tableau Today Function

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

`TODAY()`

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

### 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]))`

You can see the Tableau MakeDate Function result

### 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)`

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

### 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])`

Let me add this MakeDateTime function field to table

### 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])`

You can see the result of this IsDate function

### 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())`

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

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

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])`

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 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])`

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

`DATEPART('hour', [HireDate])`

### 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])`

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

`DATENAME('weekday', [HireDate])`

### 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])`

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])`