Master Tableau From Scratch

Learn Tableau fundamentals, data connections, data preparation, filtering, data modeling, calculations, LOD expressions, visualizations, dashboards, and storytelling through structured practical lessons.

COURSE SYLLABUS

Date Functions in Tableau

Learn how to work with date and time data in Tableau using built-in date functions. Understand date extraction, date truncation, date differences, date calculations, date formatting and practical time-based business analysis.

1. Introduction to Date Functions

Date Functions in Tableau are used to perform calculations and analysis on date and time fields. They help users extract date components, calculate differences between dates, add or subtract time intervals and group records by specific date levels.

Date functions are important when working with business datasets containing Order Date, Shipping Date, Delivery Date, Joining Date and other time-related information.

Why Are Date Functions Used?

  • Extract year, month, quarter and day from a date.
  • Calculate the number of days between two dates.
  • Add or subtract days, months and years.
  • Calculate monthly, quarterly and yearly sales.
  • Identify the first and last dates of a reporting period.
  • Analyze order processing and delivery time.
  • Create date-based filters and calculated fields.
  • Support trend analysis and forecasting.
Important: Tableau provides several date functions, and each function performs a different operation. Choose the function based on whether you need to extract, group, compare or modify dates.

2. Understanding Date and Time Data Types

Before using date functions, it is important to understand the date and time data types supported by Tableau.

Data Type Description Example
Date Stores calendar date information. 2026-11-04
Date & Time Stores both date and time information. 2026-11-04 14:30:00
String Text that may contain date-like values. November 04, 2026
Integer Numeric values sometimes used to represent date parts. 2026

Example Dataset

Order ID Order Date Ship Date Sales
10012026-01-052026-01-0815000
10022026-02-102026-02-1420000
10032026-03-152026-03-1812000
10042026-04-202026-04-2518000

In this dataset, Order Date and Ship Date can be used to calculate shipping duration, monthly sales and other date-based business metrics.

3. Important Date Functions in Tableau

Tableau provides several built-in date functions. The following functions are commonly used in reporting and business analysis.

Function Purpose
DATEPART() Extracts a specific part of a date as an integer.
DATENAME() Returns the name of a date part as text.
DATETRUNC() Truncates a date to a specified date level.
DATEDIFF() Calculates the difference between two dates.
DATEADD() Adds or subtracts a specified interval from a date.
DATE() Converts an expression into a date value.
DATEPARSE() Converts text into a date using a specified format.
MAKEDATE() Creates a date from year, month and day values.
TODAY() Returns the current date.
NOW() Returns the current date and time.
ISDATE() Checks whether a value can be interpreted as a date.

4. DATEPART() Function

DATEPART() extracts a specific component of a date and returns it as an integer. It is useful when you need numeric date components for calculations, filtering or comparisons.

Syntax

DATEPART(date_part, date)

Example: Extract Year

DATEPART('year', [Order Date])

Example: Extract Month

DATEPART('month', [Order Date])

Example: Extract Day

DATEPART('day', [Order Date])

Supported Date Parts

Date Part Meaning Example Result
'year'Year2026
'quarter'Quarter number1
'month'Month number11
'day'Day of month4
'week'Week number45 (depending on week settings)
'weekday'Day of week number4 (depending on week settings)
'hour'Hour14
'minute'Minute30
'second'Second0

Practical Example

Suppose a sales manager wants to analyze sales by year. Create a calculated field named Order Year.

DATEPART('year', [Order Date])

Drag Order Year into the worksheet to group or filter records using the extracted year.

Business Use Case: DATEPART() is useful for year-based comparisons, monthly reporting, quarter analysis and extracting numeric date components.

5. DATENAME() Function

DATENAME() returns the name of a specified date component as a string. Unlike DATEPART(), which returns a numeric value, DATENAME() returns text.

Syntax

DATENAME(date_part, date)

Example: Month Name

DATENAME('month', [Order Date])

Example: Weekday Name

DATENAME('weekday', [Order Date])

Example: Quarter Name

DATENAME('quarter', [Order Date])

DATEPART vs DATENAME

Function Expression Result Type Example
DATEPART DATEPART('month', [Order Date]) Integer 11
DATENAME DATENAME('month', [Order Date]) String November
Remember: Use DATEPART() when a numeric date component is required. Use DATENAME() when you need a readable date-part name.

6. DATETRUNC() Function

DATETRUNC() truncates a date to a specified date part. It removes the smaller date components while preserving the selected level.

For example, truncating a date to the month level returns the first day of that month. Truncating to the year level returns the first day of that year.

Syntax

DATETRUNC(date_part, date)

Example: Month

DATETRUNC('month', [Order Date])

Example: Year

DATETRUNC('year', [Order Date])

Example: Quarter

DATETRUNC('quarter', [Order Date])

Example Results

Original Date Expression Result
2026-11-04 DATETRUNC('month', date) 2026-11-01
2026-11-04 DATETRUNC('year', date) 2026-01-01
2026-11-04 DATETRUNC('quarter', date) 2026-10-01

Practical Example: Monthly Sales Grouping

DATETRUNC('month', [Order Date])

This calculation groups dates into monthly periods. It is useful when different dates within the same month must be summarized together.

Business Use Case: DATETRUNC() is commonly used for monthly revenue reports, quarterly business reviews and yearly sales analysis.

7. DATEDIFF() Function

DATEDIFF() calculates the difference between two dates using a specified date part. It is useful for measuring the time between business events.

Syntax

DATEDIFF(date_part, start_date, end_date)

Example: Difference in Days

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

Example: Difference in Months

DATEDIFF('month', [Start Date], [End Date])

Example: Difference in Years

DATEDIFF('year', [Joining Date], [Today Date])

Example Dataset

Order ID Order Date Ship Date Shipping Days
10012026-01-052026-01-083
10022026-02-102026-02-144
10032026-03-152026-03-183
10042026-04-202026-04-255

Calculated Field: Shipping Duration

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

The expression calculates the difference between Order Date and Ship Date in days.

Common Date Parts Used with DATEDIFF

  • 'year' - Difference in year boundaries.
  • 'quarter' - Difference in quarter boundaries.
  • 'month' - Difference in month boundaries.
  • 'week' - Difference in week boundaries.
  • 'day' - Difference in day boundaries.
  • 'hour' - Difference in hour boundaries.
  • 'minute' - Difference in minute boundaries.
  • 'second' - Difference in second boundaries.
Important: DATEDIFF() counts date-part boundaries, not necessarily complete elapsed periods. For example, two dates separated by a few hours can cross a day boundary. Choose the correct date part and interpret the result carefully.

8. DATEADD() Function

DATEADD() adds or subtracts a specified number of date intervals from an existing date. It is useful for creating future dates, calculating deadlines and comparing previous reporting periods.

Syntax

DATEADD(date_part, interval, date)

Add 7 Days

DATEADD('day', 7, [Order Date])

Subtract 1 Month

DATEADD('month', -1, [Order Date])

Add 1 Year

DATEADD('year', 1, [Order Date])

Example Results

Original Date Expression Result
2026-11-04DATEADD('day', 7, date)2026-11-11
2026-11-04DATEADD('month', 1, date)2026-12-04
2026-11-04DATEADD('year', 1, date)2027-11-04
2026-11-04DATEADD('day', -5, date)2026-10-30

Practical Example: Delivery Deadline

DATEADD('day', 7, [Order Date])

This expression calculates a delivery deadline seven days after the order date.

Business Use Case: DATEADD() is useful for delivery deadlines, contract expiry dates, payment due dates and previous-period comparisons.

9. DATE() Function

DATE() converts an expression into a date value when Tableau can interpret the expression as a date.

Syntax

DATE(expression)

Example

DATE([Order Date])

This expression converts the field into a Date value, removing the time portion when converting a Date & Time value to a date.

Example: Convert a Date & Time Field

DATE([Order Timestamp])
Use Case: DATE() is helpful when a source field contains date and time information but the analysis requires only the calendar date.

10. DATEPARSE() Function

DATEPARSE() converts a text value into a date using a specified format. It is useful when dates are stored as strings and Tableau cannot automatically interpret them.

Syntax

DATEPARSE(format, string)

Example: Day-Month-Year

DATEPARSE('dd-MM-yyyy', [Date Text])

Example: Year-Month-Day

DATEPARSE('yyyy-MM-dd', [Date Text])

Example: Month/Day/Year

DATEPARSE('MM/dd/yyyy', [Date Text])

Example Dataset

Date Text Format Parsed Date
04-11-2026dd-MM-yyyy2026-11-04
2026-11-04yyyy-MM-dd2026-11-04
11/04/2026MM/dd/yyyy2026-11-04

How to Create a Parsed Date

  1. Open the Tableau worksheet.
  2. Locate the text field containing date values.
  3. Create a new calculated field.
  4. Enter a meaningful name such as Converted Order Date.
  5. Write the DATEPARSE expression using the matching format.
  6. Click Apply or OK.
  7. Verify that Tableau recognizes the result as a date.
Important: The format string must match the actual text format. DATEPARSE availability and supported formats can depend on the data connection and connector.

11. MAKEDATE() Function

MAKEDATE() creates a date value from separate year, month and day values. It is useful when date components are stored in different fields or numeric columns.

Syntax

MAKEDATE(year, month, day)

Example

MAKEDATE(2026, 11, 4)

Using Dataset Fields

MAKEDATE([Year], [Month], [Day])

Example

Year Month Day Created Date
20261142026-11-04
202612152026-12-15
20271102027-01-10
Business Use Case: MAKEDATE() is useful when a dataset stores year, month and day separately and a single date field is required.

12. TODAY() and NOW() Functions

TODAY() and NOW() return the current date and current date-time values respectively. These functions are useful for dynamic reporting and time-sensitive calculations.

TODAY()

TODAY()

Returns the current date.

NOW()

NOW()

Returns the current date and time.

Practical Example: Days Since Order

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

This expression calculates the difference in day boundaries between an order date and the current date.

Practical Example: Days Until Delivery Deadline

DATEDIFF('day', TODAY(), [Delivery Deadline])

This expression calculates the difference in day boundaries between today and the delivery deadline.

Practical Example: Current Timestamp

NOW()

This can be used when the analysis needs the current date and time rather than only the date.

Remember: TODAY() returns a date, while NOW() returns a date-time value. Their results may depend on the execution environment and data connection.

13. ISDATE() Function

ISDATE() checks whether a given expression can be interpreted as a valid date. It returns a Boolean result: True or False.

Syntax

ISDATE(expression)

Example

ISDATE([Date Text])

Example Results

Date Text ISDATE Result
2026-11-04True
November 04, 2026True, if recognized by the environment
Not a dateFalse
Business Use Case: ISDATE() can help validate date-like text values before using them in date calculations.

14. Practical Business Example: Order and Delivery Analysis

Consider an e-commerce company that wants to analyze its order processing and delivery performance. The dataset contains Order Date, Ship Date, Delivery Date and Sales.

Calculation 1: Extract Order Year

DATEPART('year', [Order Date])

Extracts the year from the order date.

Calculation 2: Extract Order Month Name

DATENAME('month', [Order Date])

Returns the month name for reporting.

Calculation 3: Monthly Order Period

DATETRUNC('month', [Order Date])

Groups dates into monthly periods.

Calculation 4: Shipping Duration

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

Calculates the difference in day boundaries between order and ship dates.

Calculation 5: Delivery Deadline

DATEADD('day', 7, [Order Date])

Calculates a date seven days after the order date.

Calculation 6: First Day of the Order Year

DATETRUNC('year', [Order Date])

Returns the first date of the order year.

Dashboard Creation Steps

  1. Connect Tableau to the order dataset.
  2. Check the data types of all date fields.
  3. Create calculated fields for the required date functions.
  4. Create a worksheet for monthly sales.
  5. Create a worksheet for yearly sales.
  6. Create a worksheet for shipping duration.
  7. Create a worksheet for delivery deadlines.
  8. Combine the worksheets into a dashboard.
  9. Add date filters for interactive analysis.
  10. Validate the calculations against the source data.

Example Order Performance Summary

Total Orders 4
Total Sales 65000
Average Shipping Days 3.75
Longest Shipping Time 5 Days

Illustrative metrics based on the four sample orders used in this lesson.

15. Common Errors and Troubleshooting

Problem Possible Reason Solution
Date function returns an error Incorrect syntax or field reference. Verify the function syntax and field names.
DATEPART returns unexpected values Wrong date part or date field. Check the date component being extracted.
DATENAME returns unexpected text Locale or date-part settings differ. Review the date format and locale settings.
DATEPARSE returns Null Format string does not match source text. Use the exact format of the source date string.
DATEDIFF gives unexpected results Date-part boundary counting is misunderstood. Check the date part and start/end date order.
DATEADD returns an unexpected date Wrong interval or date part. Verify the interval value and date part.
Date field is treated as text Source data type is incorrect. Convert or parse the text into a date value.
ISDATE returns False Input cannot be interpreted as a date. Check the source value and supported date format.

16. Best Practices for Date Functions

  • Verify that date fields have the correct data type.
  • Use DATEPART() for numeric date components.
  • Use DATENAME() for readable date-part names.
  • Use DATETRUNC() for period-based grouping.
  • Use DATEDIFF() for date-part difference calculations.
  • Use DATEADD() for date interval calculations.
  • Match DATEPARSE() formats with the original text.
  • Validate results with sample records.
  • Consider locale and week-start settings when analyzing weeks.
  • Use clear names for date-related calculated fields.
  • Check null values and invalid dates before analysis.
  • Test date calculations using different reporting periods.

17. Practical Exercise

Use a sales dataset containing Order Date, Ship Date, Delivery Date, Customer and Sales fields. Complete the following tasks to practice Tableau date functions.

Exercise 1: Extract Year

Create a calculated field that extracts the order year.

DATEPART('year', [Order Date])

Exercise 2: Extract Month Name

Create a field that returns the order month name.

DATENAME('month', [Order Date])

Exercise 3: Create Monthly Period

Group all order dates into monthly periods.

DATETRUNC('month', [Order Date])

Exercise 4: Calculate Shipping Duration

Calculate the difference between order date and ship date.

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

Exercise 5: Calculate Delivery Deadline

Create a deadline seven days after the order date.

DATEADD('day', 7, [Order Date])

Exercise 6: Convert Text into Date

Convert a text field formatted as DD-MM-YYYY.

DATEPARSE('dd-MM-yyyy', [Date Text])

Exercise 7: Create a Date from Separate Fields

Combine Year, Month and Day into one date field.

MAKEDATE([Year], [Month], [Day])

Summary

Date Functions in Tableau help users extract, group, compare, modify and validate date and time values. DATEPART() extracts numeric date components, DATENAME() returns readable date-part names, DATETRUNC() groups dates at a specified level, DATEDIFF() calculates differences between dates and DATEADD() adds or subtracts date intervals. DATE(), DATEPARSE() and MAKEDATE() support date conversion and creation, while TODAY() and NOW() provide current date and date-time values. These functions are useful for monthly and yearly sales reports, delivery analysis, order processing and other time-based business calculations. In the next lesson, you will learn the difference between Continuous and Discrete Dates in Tableau.