Extract clock time from datetime in Tableau

How to pull clock time out of a Tableau datetime: formatting vs calculated fields, what each changes, and how the result sorts, exports and reads.

Tableau has date and date-and-time data types, but no time-only type. To work with clock time, you either hide the date part through formatting or build a calculated field that represents the time some other way. Each approach changes something different, and that affects sorting, filtering, aggregation and export. This review explains what each method changes so you can pick one that fits your use.

Which approach to use

For most analysis, the best choice is a calculated field that moves every timestamp onto one fixed anchor date and then applies a time-only format. Times from different days then line up, sort chronologically and stay continuous on an axis. The tradeoff is that the field still holds a full datetime. If it leaves Tableau without its formatting, the anchor date appears.

Use the other methods when the anchor-date approach is more than you need:

  • Formatting only: when you just want to hide the date on a view that is already scoped to one day.
  • The Hour (or Minute) date part: when hour-of-day buckets are enough, such as a count of events by hour.
  • Seconds since midnight: when you need averages, differences or binning of times as numbers.
  • A plain-text time string: only for labels, tooltips or exports where the destination must show exactly 'HH:MM' and no calculation will be done on it.

What each method actually changes

Some methods change only how a value is displayed. Others create a new value with a different meaning or data type. This difference explains most of the surprises people run into.

Method | What changes | Resulting type | Times from different days comparable?
Custom date format on the original field | Display only; the stored value keeps its date | Date & Time | No; sorting and filtering still use the full timestamp
Hour/Minute date part on the pill | The view groups values by that part | Discrete or continuous date part | Yes, at the chosen granularity only
Anchor-date calculated field | New value: original time on a fixed date | Date & Time | Yes
Seconds-since-midnight calculation | New value: elapsed seconds | Number (integer) | Yes
String built from date parts | New value: text | String | Only if zero-padded; no time arithmetic

Formatting the original field

In the Format pane or the field's default properties, you can choose a custom date format that shows only hours, minutes and seconds. In Tableau's format syntax, minutes are usually written as 'nn' because 'mm' means month. One example is the following, but check the symbol set against the date format reference for your Tableau version.

hh:nn:ss AMPM

The value itself does not change. Two marks that both show 09:15 AM can come from different days, sort apart from each other and appear as separate points on a continuous axis. Use this method when the date part truly does not matter for the view.

Using the Hour date part

Right-click a datetime pill and choose a discrete Hour date part, or look under the More options for Minute and Second. Tableau then groups values by hour of day, from 0 to 23, across all dates. This is the simplest method for patterns like 'orders by hour'. It does not keep the exact clock time, and the continuous version of Hour truncates timestamps but keeps the date, so it does not merge days.

Moving times onto an anchor date

This calculation measures how far each timestamp is from its own midnight. It then adds that offset to one fixed datetime. The 1899-12-30 anchor is a common convention because it matches day zero in spreadsheet date serials, but any fixed date works as long as you use it consistently. Replace [Order Datetime] with your field name.

DATEADD('second',
    DATEDIFF('second', DATETRUNC('day', [Order Datetime]), [Order Datetime]),
    #1899-12-30 00:00:00#)

Give the result a time-only format and it acts like a clock-time field: one shared axis, chronological sorting and range filters that work across days. Some data sources also support MAKEDATETIME, which combines a date with the time portion of another value. Tableau documents that its availability depends on the connection type, so confirm it is supported for your source before you rely on it.

MAKEDATETIME(#1899-12-30#, [Order Datetime])

Seconds since midnight

When you want to calculate with times, a plain number is often easier than a datetime. You can average it, bin it or subtract one value from another. Divide by 3600 to get hours.

DATEDIFF('second', DATETRUNC('day', [Order Datetime]), [Order Datetime])

The number is not readable as a clock time without converting it back. Use it for calculations and use the anchor-date field for display.

A text time string

Converting a datetime with STR alone can produce output that varies with locale and data source. Building the string from date parts gives predictable output. Zero-padding matters because text sorts character by character, so '9:05' would otherwise sort after '10:00'.

RIGHT('0' + STR(DATEPART('hour', [Order Datetime])), 2) + ':' +
RIGHT('0' + STR(DATEPART('minute', [Order Datetime])), 2)

The result is text, not a time. It cannot go on a continuous axis, take part in date arithmetic or be used in a range filter. It is also 24-hour unless you add AM/PM logic yourself.

Caveats shared by all methods

  • Time zone: none of these calculations converts time zones. If the source stores UTC, the extracted clock time is UTC.
  • Sub-second precision: the seconds-based formulas drop fractions of a second. Use a finer date part only if your data source keeps that precision.
  • Nulls: a null datetime gives a null result in every calculation above. Decide how those rows should appear.
  • Daylight saving transitions: an hour can repeat or be skipped on transition days. Clock-time grouping does not resolve this.

Will the result stay readable after copying or sharing?

Formatting belongs to the workbook, not to the value. When data leaves Tableau, the destination may show the stored value instead of the display format. A formatted original field may then reappear as a full timestamp, and an anchor-date field may show 1899-12-30 next to the time. How each export path (crosstab, data download, copying from a view, a published data source) handles formatting can differ by Tableau version and destination application. No test results were supplied for this review, so check the specific path and destination you plan to use rather than assuming one successful export applies to all.

Create a plain-text equivalent, such as the zero-padded string above, when the receiving system must show the time exactly as written and will not do time calculations. Keep the anchor-date or numeric field when the receiving tool needs to sort, filter or calculate. Exporting both columns is a practical compromise.

For readability, including for people using screen readers, label the time zone and clock convention in the field name, axis title or tooltip, for example 'Order time (UTC, 24-hour)'. This matters more than the format string itself. Ambiguous labels like '12:00' with no AM/PM cause confusion whether they are read on screen or aloud. This review has no documentation or test results on how specific assistive technologies read Tableau time axes, so verify this in your own environment if accessibility is a requirement.

Gaps in this review

The material supplied for this review included no version-specific documentation, tested exports or connector behavior. The formulas above rely on documented Tableau functions and general date-handling principles. Before you depend on a method in production, confirm that it works with your data source, your Tableau version and the place the output ends up.