Tableau Date Functions

Dates drive most business questions: sales by month, delivery time in days, growth against last year. Tableau includes a set of date functions that slice, shift, and measure time with simple formulas.

Date Parts and Date Truncation

Two ideas sit behind most date work. A date part pulls out one piece of a date, such as the year. A date truncation rounds a date down to the start of a period, such as the first day of the month.

Original date: 17-Aug-2025

DATEPART('month', date)  -> 8
DATENAME('month', date)  -> "August"
DATETRUNC('month', date) -> 01-Aug-2025

Why the Difference Matters

A date part creates a repeating category. January 2024 and January 2025 both become 1. A truncated date keeps the full timeline, so Tableau places January 2024 and January 2025 at different points.

Core Date Functions

DATEPART

DATEPART returns a number for the chosen part. Use 'year', 'quarter', 'month', 'week', 'day', or 'weekday' as the first argument.

DATENAME

DATENAME returns the part as text. DATENAME('weekday', [Order Date]) returns names such as Monday and Tuesday, which read well on chart labels.

DATETRUNC

DATETRUNC rounds down to the period start. Group daily sales into monthly totals by using DATETRUNC('month', [Order Date]).

DATEDIFF

DATEDIFF counts the gap between two dates in the unit you choose.

DATEDIFF('day', [Order Date], [Ship Date])

Order Date: 01-Mar
Ship Date:  05-Mar
Result: 4 days

DATEADD

DATEADD moves a date forward or backward. DATEADD('month', 3, [Order Date]) returns a date three months later, and a negative number moves backward.

Current Date Functions

  • TODAY() returns the current date.
  • NOW() returns the current date and time.

Combine them with other functions to build rolling windows. The formula [Order Date] >= DATEADD('day', -30, TODAY()) keeps only the last thirty days.

Build Dates From Parts

MAKEDATE joins a year, month, and day into one date field: MAKEDATE(2025, 8, 17). Use it when your source stores the year, month, and day in three separate columns.

Timeline Diagram

Order Date          Ship Date           Delivery Date
    |------ 2 days ------|------ 3 days ------|
    |                                         |
    +--------------- 5 days total ------------+

DATEDIFF('day', Order, Delivery) = 5

Practical Calculations

Shipping Delay Flag

IF DATEDIFF('day', [Order Date], [Ship Date]) > 5
THEN "Late"
ELSE "On Time"
END

Year-to-Date Filter

[Order Date] >= DATETRUNC('year', TODAY())
AND [Order Date] <= TODAY()

Same Period Last Year

Shift each order date back twelve months with DATEADD('year', -1, [Order Date]). Compare the shifted values against current ones in a dual axis line chart.

Fiscal Year Settings

Some companies begin their year in April or October. Right-click the date field in the Data pane, choose Default Properties, and select Fiscal Year Start. Quarters and years then follow your company calendar.

Tips for Clean Date Work

  • Confirm the field holds a true Date type before using any date function.
  • Pick the date level in the unit argument carefully; 'week' starts on Sunday by default in many setups.
  • Test formulas on a few rows before applying them to the whole dataset.

Summary

DATEPART and DATENAME extract pieces of a date. DATETRUNC rounds dates to period starts. DATEDIFF measures gaps, and DATEADD shifts dates forward or back. TODAY and NOW anchor calculations to the present moment. Mastering these six functions covers most time-based analysis.