KNOWLEDGE BASE

Adjusting Datetime Field for Daylight Savings Time


Published: 06 Aug 2014
Last Modified Date: 14 Sep 2015

Question

How to adjust a Datetime field to include Daylight Savings Time adjustments when the data source does not provide this functionality.

Environment

Tableau Desktop

Answer

Use a calculated field similar to the following, where [Order Date] is the Datetime field that is being adjusted: 
IF [Order Date] >= DATEADD('hour', 2, (IF DATEPART('weekday', DATEADD('month', 2, DATETRUNC('year', [Order Date]))) = 1
THEN DATEADD('month', 2, DATETRUNC('year', [Order Date])) + 7
ELSE DATETRUNC('week', DATEADD('month', 2, DATETRUNC('year', [Order Date])) + 13)
END))
AND
[Order Date] <= DATEADD('hour', 2, (IF DATEPART('weekday', DATEADD('month', 10, DATETRUNC('year', [Order Date]))) = 1
THEN DATEADD('month', 10, DATETRUNC('year', [Order Date])) + 7
ELSE DATETRUNC('week', DATEADD('month', 10, DATETRUNC('year', [Order Date])) + 6)
END))
THEN DATEADD('hour', 1, [Order Date])
ELSE [Order Date]
END
For European time changes use a formula similar to the following:
IF 
//last Sunday in March at 1AM
[Date] >= DATEADD('hour',1,DATEADD('day',-1,DATETRUNC('week',DATEADD('month',3,DATETRUNC('year',[Date])))))
AND
//last Sunday in October at 2AM
[Date] < DATEADD('hour',2,DATEADD('day',-1,DATETRUNC('week',DATEADD('month',10,DATETRUNC('year',[Date])))))
THEN DATEADD('hour',1,[Date])
ELSE [Date]
END
Did this article resolve the issue?