Ask Your Question
0

how to concatenate 12 hr time and the text "AM" or "PM"

asked 2016-07-27 18:23:18 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hello, a question from an absolute amateur. I have a Calc spreadsheet file that was imported from a recording controller. It has 12 hour time in one column (eg 05:00:00), and the text "AM" or "PM" in a separate column right next to it. I had been sorting it for other work, now I can't get it to sort right by date and time. The time is in 15 minute increments. The dates sort good, but the time is simply sorting in numerical order as the AM and PM are in a separate column. So 12:00:00 | AM ends up coming after 11:45:00 | AM instead of after 11:45:00 | PM. To solve this, I need to merge the 12hr time and the text "AM", so that it reads "12:00:00 AM" in one column. Then it will automatically change the time format to 24 hr time which will sort correctly. I can do a merge on two cells, and say yes to moving the "contents of the hidden cell into the first cell", then it comes out right. But I don't want to do that a million times. And I can't just block out all the data and do the merge as it puts everything into one cell. So, 1) Is there a "MERGE" command that can be put into a formula, so I can create a 3rd column, and paste in a formula which takes the two previous columns and merges them correctly, or 2) is there a way to do CONCATENATE on the time and AM/PM text (I have tried the simple CONCATENATE(A1&B1) but it doesn't work, 5:00:00 | PM comes out as 0.208333), or any other ideas? Thanks!

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

answered 2016-07-27 23:46:42 +0100

m.a.riosv gravatar image

Something like:

image description

edit flag offensive delete link more

Comments

@m.a.riosv: (See also my comment to the answer by @mark_t) This solution will only work in specific locales accepting AM/PM notation by default. In fact the TIMEVALUE function is "locale sensitive" but not "cell-numbers-locale sensitive". How did you get the numeric A1 in this locale? (The contents in OQ's first column migh be text from the beginning.)

Lupp gravatar imageLupp ( 2016-07-28 10:34:09 +0100 )edit

This worked great...thanks so much!

KingProcessTech gravatar imageKingProcessTech ( 2016-07-28 14:04:03 +0100 )edit
0

answered 2016-07-28 11:15:12 +0100

Lupp gravatar image

Assuming the first column to contain text built from the first 8 places of time values formatted by "HH:MM:SS AM/PM" under a respective locale, a locale independent reconstruction of the correct time values as used by spreadsheets can be done this way:
=TIMEVALUE(IF(LEFT(A1;2)="12";SUBSTITUTE(A1;"12";"00";1);A1))+IF(B1="PM";1/2;0)
"Locale independent", of course, based on the column contents being in characters as descibed (ASCII conforming).

The results used for sorting will work independent of the displayed format then.

edit flag offensive delete link more
-1

answered 2016-07-28 03:23:45 +0100

mark_t gravatar image

If I correctly understand your described application I think you do not need to concatenate columns. If you use menu "Data", "Sort" then you can set three different columns to use for sorting. Set the sort columns in the order of Date, AM/PM and then Time and this should sort the data as required.

edit flag offensive delete link more

Comments

@mark_t: The AM/PM gibberish is simply too silly to allow for such a solution:
12:30 PM is eralier than 1:30 PM!

Lupp gravatar imageLupp ( 2016-07-28 09:29:48 +0100 )edit

Yes sorry, I missed the 12:30 PM issue.

mark_t gravatar imagemark_t ( 2016-07-28 17:30:45 +0100 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2016-07-27 18:23:18 +0100

Seen: 1,161 times

Last updated: Jul 28 '16