Extracting Time from a Datetime or String in Tableau
How to pull the clock time out of a datetime field or a text field in Tableau, what each method changes, and how to check that the result sorts, filters and exports correctly.
Extracting the time from a timestamp in Tableau can mean three different things: changing how the value is displayed, building a new value that keeps only the time of day, or cutting the time out of text. Each choice behaves differently when you sort, filter, aggregate or export. This guide explains what each approach actually changes and how to judge whether the result fits your use.
What extracting time actually changes
Tableau has a date type and a date-and-time type, but no separate time-only type. Every approach therefore produces one of three things: the original datetime with a different display format, a datetime set to a fixed placeholder date, or a number or string that represents part of the clock time. Knowing which one you have explains most later surprises.
- Display formatting only: the stored value keeps its date. Filters, sorting and calculations still use the full timestamp.
- New datetime on a placeholder date: the date part is replaced with a constant, so values from different days can be compared by time of day alone.
- Numeric part: DATEPART returns an integer, such as the hour, that is suitable for grouping and binning.
- String: the time becomes text. It is easy to read, but sorting, ranges and arithmetic depend on how the text is written.
Option 1: Change the display format of a datetime
If you only need labels or tooltips to show the time, apply a custom date format to the field. Open Format, choose the Dates setting for the field, and enter a custom format. In Tableau's display format strings, minutes use "nn" and months use "mm". Check the AM/PM symbol against the formatting documentation for your Tableau version.
hh:nn:ss
This approach changes appearance only. A filter on this field still selects by full date and time. If the view is set to show the field as a discrete date part, such as Year or Day, that setting controls the grouping, not the custom format.
Option 2: Get individual time parts with DATEPART or DATENAME
Use DATEPART when you need a number, for example to count events by hour. Use DATENAME when you need the same part as a string.
DATEPART('hour', [Order Datetime])
DATEPART('minute', [Order Datetime])
DATEPART('second', [Order Datetime])
DATENAME('hour', [Order Datetime])
An integer hour sorts and aggregates correctly. Only the part you request is kept, so minutes and seconds are lost unless you extract them separately.
Option 3: Build a time-of-day datetime on a fixed date
To compare times across many days on one continuous axis, move every value onto the same placeholder date. One way that uses only standard date functions is to count the seconds since midnight and add them to a constant date:
DATEADD('second',
DATEDIFF('second', DATETRUNC('day', [Order Datetime]), [Order Datetime]),
#1899-12-30#)
Then format the result with a time-only display format, as in Option 1. The placeholder date is still stored. It can appear in exports, in tooltips that use a default format, and in any calculation that reads the full value.
If you need seconds since midnight as a plain number, for example to calculate averages or durations, use the inner DATEDIFF expression by itself.
Extracting time from a string
When timestamps arrive as text, choose between converting them to a real datetime and slicing out the time as text. Converting is usually the better choice when you need sorting, ranges or arithmetic.
Convert with DATEPARSE, then extract
DATEPARSE reads a string by using a pattern you supply. Its pattern symbols follow a different convention from display formatting: "mm" means minutes and "MM" means months. "HH" is the 24-hour clock and "hh" is the 12-hour clock. Tableau documents DATEPARSE as available only for certain data source types, so confirm that your connection supports it.
DATEPARSE('yyyy-MM-dd HH:mm:ss', [Timestamp Text])
After parsing, apply any of the datetime methods above. If the pattern does not match a row, that row returns null. Count nulls before and after conversion to catch formatting problems in the source data.
Slice the time as text
If the text has a consistent layout, string functions can return the portion after the space:
MID([Timestamp Text], FIND([Timestamp Text], ' ') + 1)
TRIM(SPLIT([Timestamp Text], ' ', 2))
The result is a string. It sorts in clock order only if every value uses the 24-hour clock and leading zeros, such as 09:05 rather than 9:5. A 12-hour value such as 1:00 PM sorts as text, not by time. Use this method for display or matching, not for time ranges.
Choosing a method
| Need | Recommended method | Result type | Main caveat |
| Show only the time in labels | Custom display format | Datetime (unchanged) | Filters and sorting still use the full timestamp |
| Count or group by hour | DATEPART | Integer | Finer detail is dropped |
| Compare time of day across dates | DATEADD on a fixed date | Datetime | Placeholder date stays in the value |
| Average or measure durations | DATEDIFF in seconds since midnight | Integer | Needs conversion back for display |
| Source is text, analysis needed | DATEPARSE, then a datetime method | Datetime | Connection support; unmatched rows become null |
| Source is text, display only | MID, FIND or SPLIT | String | Text sorting, no time arithmetic |
Will the result stay readable and usable where you need it?
Check the destination before you rely on a format, because Tableau's display formatting does not always travel with the data.
- Exports and copied data: underlying data exports may contain the full stored value, including any placeholder date, rather than the formatted label. If a downstream tool needs plain time text, create a separate string field for export.
- Other tools: spreadsheets and databases may read the same text as a date, a time or a plain string, depending on their own settings. Test with a few sample rows.
- Locale and clock style: 12-hour and 24-hour output, and AM/PM text, can vary with workbook or user locale settings. If viewers in different regions see the dashboard, use an explicit custom format or a 24-hour string.
- Time zones: these calculations do not convert time zones. The extracted time reflects whatever zone the source stored.
- Accessibility: a clear, unambiguous label such as 14:30 or 2:30 PM is generally easier to read than a placeholder date with a time. How a specific screen reader announces Tableau marks depends on the product version and assistive technology; no test results were available for this guide.
Gaps to verify in your environment
This guide relies on general, documented Tableau function behavior. It does not include version-specific tests, export samples or data-source support lists. Before you publish a dashboard, confirm three things in your version and connection: that DATEPARSE is available, which AM/PM format symbol your version uses, and how exported files represent the extracted field.