Understanding Date Functions in Tableau : Part 1

In the previous post we discussed about Logical functions in Tableau . Today we will go ahead with the date functions available in Tableau. To make things simple we would cover half in this post and the remaining half date function in the next article.
Many date functions use date_part , which is a constant string argument. The valid date_part values that we can use are as under :

Lets examine the different date functions available in Tableau now:

Syntax : DATEADD(‘date_part’,interval,date)
The DATEADD function allows us to specify a portion of a date and increase it. The number that we use for the interval will change the date by increasing the date_part.
Lets  consider the following examples :
As we can see in the first function we add 4 days to the date 2016-04-10 which results in 14 Apr 2016. Similarly in the second case we see that 3 months are being added to the date 2016-04-10.

Syntax : DATEDIFF(‘date_part’,start date,end date, [start of week])
This function returns the difference between two dates where start date is subtracted from the end date. The difference is expressed in the units of the date_part. The start of the week is optional .
The following example illustrates the above fact:date3
We can see above that the first function gives the difference between the dates in number of days as the date_part in this case is day while in the second case the difference is expressed in months as we have the date_part as month.

Syntax: DATENAME(date_part,date,[start of week])
This function returns a part of the given date as string , where the part is defined by date_part.
Following example illustrates the output with a sample date 2015-05-28

Syntax: DATEPART(date_part,date,[start of week])
This function returns a part of the given date as an integer where the part is defined by date_part. If the start of the week is omitted , the week start date is determined by the start date configured for the data source.
Following example illustrated the output of this function with a sample date 2015-05-28.

Hope you find this post interesting. The remaining date functions we would discuss in the next article.


Please follow and like us: