Get time in am/pm format

Changing the time in your column to an am/pm format is straightforward, just follow the steps below or check out the video walkthrough.

  1. Extract the hour from your column that has the time in in by using the column dropdown, selecting extract, and then selecting hour.
  2. Next, add a new column, and use this formula: 
    if(extract_hour > 12) then "pm" else "am"
    This will segment each row into either am or pm
  3. Now change the formatting of the datetime column to year-month-day time using the column dropdown or by using this formula:
    your_column_name.format("YYYY-MM-DD HH24:MI")
  4. Extract the time from this column using this formula:
    your_column_name.extract(" (.*)")
    Which will pull the time section from the column, as it extracts all info after a space.
  5. Now we have a column with the times, e.g. 19:25, 7:46, etc. and another column with either am or pm. All we need to do is combine these columns by adding a new column and using '+' to combine them:
    your_time_column_name + your_ampm_column_name
  6. Now you should have a column with 19:25pm, 7:46am and so on.

Note: always remember to change the 'your_column_name' parts of the formulas to the actual column name that you're using. 

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.