KNOWLEDGE BASE

Date Calculations, Filters, and Time Stamps Show Unexpected Results After Publishing


Published: 01 Oct 2013
Last Modified Date: 09 May 2023

Issue

After publishing a workbook or data source, calculations based on NOW() or TODAY(), Relative Date Filters, and time stamps (such as last updated) show unexpected results. The calculations, filters, and time stamps appear to be computed in a different timezone.

Environment

  • Tableau Cloud
  • Tableau Server

Resolution

If using Extracts and the date is calculated using the NOW() or TODAY() functions

  1. In a web browser, login to Tableau Cloud or Tableau Server as a Site Administrator.
  2. Select Settings and on the General tab scroll down to the Site Time Zone for Extracts section.
  3. Specify the desired time-zone. See Set the Site Time Zone for Extracts for more information. 


To adjust the time zone of date and date/time fields that are displayed in the view:

  1. Open the workbook in Tableau Desktop.
  2. Select Analysis > Create Calculated Field.
    • For a date/time field, create a calculation similar to the following:
      DATEADD('hour',<number of hours>,[<datetime field>])
    • For a date only field, create a calculation similar to the following:
      IF DATEPART('hour', NOW()) > <PST time of midnight> then DATEADD('day', 1, <datetime field>) else <datetime field> end
      • ​For example: IF DATEPART('hour', NOW()) > 6 THEN DATEADD('day', 1, [Date]) else [Date] END This expression adds one more day to the date field called "Date" if the time is superior to 6 hours past midnight, otherwishe the date remains the same. 
      • For more information about the date functions DATEPART or DATEADD, see Date Functions in Tableau Help. 
  3. Replace the date/time field used in the view with the newly created calculated field.
  4. Re-publish the workbook or data source.


To replace a Relative Date Filter with a calculation that filters to the most recent hour in the dataset:

  1. Create a calculation such as the following:
    [DateTimeField] >= {FIXED: MAX(DATETRUNC('hour',[DateTimeField]))} 
  2. Place the calculation on the Filter Shelf, choose to show "True" 


To replace a Relative Date Filter with a calculation that filters to "this hour" in the desired timezone:

  1. Create calculation such as the following. Note, the following converts from Pacific Time (Tableau Cloud 10ay) to Eastern Time (hypothetical user):
    [DateTimeField] >= DATEADD('hour', 3, NOW()) 
  2. Place the calculation on the Filter Shelf, choose to show "True" 

Cause

After publishing a data source or workbook, NOW(), TODAY(), Relative Date Filters, and time stamps are localized to the timezone of the Tableau Server or Tableau Cloud.

Additional Information

The number of hours to shift the time may change if you're area observes Daylight Savings. The following calculation converts UTC to Pacific time, assuming Daylight Savings starts the 2nd Sunday of March and ends the 1st Sunday of November):
DATEADD('hour',
IF [<datetime field>] <= IFNULL(
    { FIXED DATETRUNC('year', [<datetime field>]) : MIN(
    IF DATEPART('month', [<datetime field>]) = 3
    THEN
    DATEADD('minute', 119, DATEADD('day',    IF DATEPART('weekday', DATETRUNC('month', [<datetime field>])) >1
    THEN 7 - (DATEPART('weekday', DATETRUNC('month', [<datetime field>])) - 1)
    ELSE 0
    END
    + 7,    DATETRUNC('month', [<datetime field>])
    ))
    END
    )}
, TODAY()+1)
OR [<datetime field>] >=
    { FIXED DATETRUNC('year', [<datetime field>]) : MIN(IF DATEPART('month', [<datetime field>]) = 11
    THEN
    DATEADD('minute', 119, DATEADD('day',    IF DATEPART('weekday', DATETRUNC('month', [<datetime field>])) >1
    THEN 7 - (DATEPART('weekday', DATETRUNC('month', [<datetime field>])) - 1)
    ELSE 0
    END,    DATETRUNC('month', [<datetime field>])
    ))
    END
    )}
THEN -8
ELSE -7
END,
[<datetime field>])

For more information, see:


 
Did this article resolve the issue?