# 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

### Year

The Tableau YEAR function is used to return Year from the given date and the syntax of this 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.

### MONTH

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

`MONTH(Date)`

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

`MONTH([HireDate])`

Let me add this Month Number field to the Rows shelf

### DAY

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

`DAY(Date)`

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

`DAY([HireDate])`

Next, we added the day field to the Row Shelf

### NOW

The Tableau NOW function is used to return today’s date and time and the syntax of this NOW 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

### Today

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

`TODAY()`

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

### MakeDate Function

The Tableau MakeDate function is used to return date from the year, month, and day and the syntax of this MakeDate 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 MakeDate result

### MakeTime Function

The Tableau MakeTime function is used to return time from an hour, minute, and seconds and the syntax of this MakeTime 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.

### MakeDateTime Function

The Tableau MakeDateTime function is used to return date and time from Date, Time and the syntax of this MakeDateTime 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 field to table

### 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 IsDate is:

`ISDATE(string)`

Let me use this one 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

### 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 datediff function accepts YEAR, MONTH, DAY etc. For example, if you select YEAR, the DateDiff will return the number of years between a start date and end date.

The syntax of this DATEDIFF is:

`DATEDIFF(Difference_term, Start_Date, End_Date)`

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

`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 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 DATEADD function accepts YEAR, MONTH, DAY, etc. For example, if you select Month as the first argument and interval as 6, then the Dateadd will add six months to the existing date.

The syntax of the 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 the DATEADD. the below statement adds 6 months to HireDate.

`DATEADD('month', 6, [HireDate])`

### 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 DatePart function accepts YEAR, MONTH, DAY etc. For example, if you select Month as date part, then the DatePart function will return a year from a given date.

The syntax of this 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. The Below statement will return Hour from HireDate

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

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

### DATETRUNC

The Tableau DATETRUNC is one of the 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 datetrunc accepts YEAR, MONTH, DAY, etc.

The syntax of the 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 DATETRUNC. Below statement will return the first day of the quarter that the date belongs to

`DATETRUNC('quarter', [HireDate])`