Last Modified Date: 29 Nov 2023
Environment
Tableau DesktopAnswer
These directions use sample bus departures data, where the 24 hour timestamp is saved in a numeric field, such as 835 for 8:35 am. You may not need all of the following steps if your 24 hour timestamp is already a string field (aka text type) with a leading zero.
- Right-click [Scheduled Departure Time] in the left-hand data pane and select Convert to Dimension
- Click the # icon next to [Scheduled Departure Time] in the data pane, and select String
- Select Analysis > Create Calculated Field
- In the Calculated Field dialog box that opens, do the following, and then click OK:
- Name the calculated field. In this example, the calculated field is named "Scheduled Departure Time (dateparse)"
- In the formula field, create a calculation similar to the following:
DATEPARSE("hmm",[Scheduled Departure Time]) //if the data contains a leading zero then use "hhmm" instead of "hmm"
- DATEPARSE() is not available in all data sources. If DATEPARSE() is not available then use DATETIME() instead. In this example, the calculated field "Scheduled Departure Time (datetime)" uses the following calculation:
DATETIME( "1/1/1900 " //arbitrary date + IF LEN([Scheduled Departure Time]) = 3 THEN "0" ELSE "" END //add a leading zero if the timestamp is only 3 characters long + [Scheduled Departure Time] )
- Right-click [Scheduled Departure Time (dateparse)] or [Scheduled Departure Time (datetime)] in the left-hand data pane, and select Default Properties > Date Format...
- In the Default Date Format dialog, do the following and click OK:
- Click Custom
- In the Format field, type in the desired time format such as hh:nn AMPM. See Supported date format symbols for all possible options.
Additional Information
- Tableau does not have a "time" field type, but time data (either as a string or a number) can be converted into a Date & Time field and then formatted to appear as just a timestamp.
- If the original field already includes a date, then it may be possible to convert the field to a Date & Time field by clicking the Abc icon next to the field name in the data pane and selecting Date & Time
Thank you for providing your feedback on the effectiveness of the article.
Open new Case
Continue Searching
Knowledge Base
Community
Product Help
Training and Tutorials