Loading

How to Change Military Time Into Standard 12-Hour Time Format

Publiseringsdato: Apr 13, 2024
Oppgave
How to convert a numeric value that is a military or 24 hour timestamp into a datetime field using the 12 hour format
Trinn

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. 

  1. Right-click [Scheduled Departure Time] in the left-hand data pane and select Convert to Dimension
  2. Click the # icon next to [Scheduled Departure Time] in the data pane, and select String
  3. Select Analysis > Create Calculated Field
  4. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Scheduled Departure Time (dateparse)"
    2. 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"
      
    3. 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]
      )
      
  5. Right-click [Scheduled Departure Time (dateparse)] or [Scheduled Departure Time (datetime)] in the left-hand data pane, and select Default Properties > Date Format...
  6. In the Default Date Format dialog, do the following and click OK:
    1. Click Custom
    2. In the Format field, type in the desired time format such as hh:nn AMPM. See Supported date format symbols for all possible options.
Flere ressurser
  • 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
DATEPARSE Function Not Available
Knowledge-artikkelnummer

001458087

Vedlegg

24hr to 12hr timestamp_v2022.1.twbx

33 KB

 
Laster
Salesforce Help | Article