+ Reply to Thread
Results 1 to 15 of 15

CONCATENATE Time Cells

  1. #1
    Registered User
    Join Date
    08-24-2006
    Posts
    48

    CONCATENATE Time Cells

    Hi All:

    How do I concatenate two cells that are formatted to TIME, but remove the "AM" and "PM"?

    Here's what I have:

    Cell A1: 8:00 AM
    Cell B1: 4:00 PM

    In cell G1, I want to concatenate the two and drop the "AM" and "PM" so that it only shows "8:00 - 4:00"

    I'm currently using:

    =CONCATENATE(A1," - ",B1)

    ... yet my output in G1 is: "0.333333333333333 - 0.666666666666667"

    I want ... "8:00 - 4:00"

    Thank you!

    Last edited by ExcelJunkie; 09-18-2006 at 01:45 PM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Would this work for you

    =CONCATENATE(TEXT(A1,"hh:mm")&" - ",TEXT(B1,"hh:mm"))

    VBA Noob

  3. #3
    Valued Forum Contributor
    Join Date
    03-25-2004
    Location
    Boston, MA US
    Posts
    1,094
    You could try this as long as your start time is always AM and the end time is always PM,

    =A1*24&":00"&" - "&((B1*24)-12)&":00"


    This would return 8:00 - 4:00. I believe the last post would return the 4:00 PM as 16:00.


    HTH

    Steve

  4. #4
    Registered User
    Join Date
    08-24-2006
    Posts
    48
    Thank you both so much, but the start time will end in both AM and PM.

    I could have:

    4:00 PM
    12:00 AM

    which I would still want "4:00 - 12:00"

    So, how would I do it then?

    Steve G: You are correct, VBA Noob's code works great but shows "8:00 - 16:00", this may confuse the non-military time reading folks.

    Thank you, thank you!

    Last edited by ExcelJunkie; 09-18-2006 at 02:41 PM.

  5. #5
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097

    Thumbs up

    Quote Originally Posted by ExcelJunkie
    Hi All:

    How do I concatenate two cells that are formatted to TIME, but remove the "AM" and "PM"?

    Here's what I have:

    Cell A1: 8:00 AM
    Cell B1: 4:00 PM

    In cell G1, I want to concatenate the two and drop the "AM" and "PM" so that it only shows "8:00 - 4:00"

    I'm currently using:

    =CONCATENATE(A1," - ",B1)

    ... yet my output in G1 is: "0.333333333333333 - 0.666666666666667"

    I want ... "8:00 - 4:00"

    Thank you!

    Hi ExcelJunkie,

    Formula in C1

    =(A1*24)-12&":00"&" - "&(B1*24)-12&":00"

    oldchippy

  6. #6
    Registered User
    Join Date
    08-24-2006
    Posts
    48
    Thank you OldChippy!

    All of you rock! Thanks for such fast responses. I really appreciate you folks!

    However, your code outputs:

    -4:00 - 4:00


  7. #7
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Quote Originally Posted by ExcelJunkie
    Thank you OldChippy!

    All of you rock! Thanks for such fast responses. I really appreciate you folks!

    However, your code outputs:

    -4:00 - 4:00

    When you enter 8:00 don't forget to add the PM, or it will think it is 4:00 AM

    You'll find it will work then

  8. #8
    Registered User
    Join Date
    08-24-2006
    Posts
    48
    Thank you again!

    Your code works if the start time is PM. However, I have exactly:

    8:00 AM
    4:00 PM

    it outputs -4:00 - 4:00. I need something that will work regardless of the time of day for start time, whether AM or PM.


  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    How about

    =CONCATENATE(TEXT(A1,"hh:mm AM/PM")&" - ",TEXT(B1,"hh:mm AM/PM"))

    VBA Noob

  10. #10
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    or

    =SUBSTITUTE(CONCATENATE(TEXT(A1,"hh:mm")&" - ",TEXT(B1,"hh:mm AM/PM")),"PM","")


    VBA Noob

  11. #11
    Valued Forum Contributor
    Join Date
    03-25-2004
    Location
    Boston, MA US
    Posts
    1,094
    TEXT(A1,"hh:mm") will return a zero if the time in A1 is 12:00 AM. the problem is that you have 9 different scenarios possible here. Your start time could be less than 12 AM, equal to 12 AM or greater than 12 AM as could your end times. There certainly could be a better way but if you want you could set up a table with the following formulas. I used this in H1:H9.

    =(A1*24)&":00"&" - "&(B1*24)&":00"
    =(A1*24)&":00"&" - "&(B1*24)+12&":00"
    =(A1*24)&":00"&" - "&((B1*24)-12)&":00"
    =(A1*24)+12&":00"&" - "&(B1*24)&":00"
    =(A1*24)+12&":00"&" - "&(B1*24)+12&":00"
    =(A1*24)+12&":00"&" - "&((B1*24)-12)&":00"
    =((A1*24)-12)&":00"&" - "&(B1*24)&":00"
    =((A1*24)-12)&":00"&" - "&(B1*24)+12&":00"
    =((A1*24)-12)&":00"&" - "&((B1*24)-12)&":00"

    These account for the 9 different scenarios.

    In F1:F9 input the following formulas.

    =IF(AND(($A$1*24)<12,($A$1*24)<>0,($B$1*24)<12,($B$1*24)<>0),1,"")
    =IF(AND(($A$1*24)<12,($A$1*24)<>0,($B$1*24)=0),2,"")
    =IF(AND(($A$1*24)<12,($A$1*24)<>0,($B$1*24)>12),3,"")
    =IF(AND(($A$1*24)=0,($B$1*24)<12,($B$1*24)<>0),4,"")
    =IF(AND(($A$1*24)=0,($B$1*24)=0),5,"")
    =IF(AND(($A$1*24)=0,($B$1*24)>12,($B$1*24)<>0),6,"")
    =IF(AND(($A$1*24)>12,($B$1*24)<12,($B$1*24)<>0),7,"")
    =IF(AND(($A$1*24)>12,($B$1*24)<12,($B$1*24)<>0),8,"")
    =IF(AND(($A$1*24)>12,($B$1*24)>12),9,"")

    Then in G1 I entered,

    =CHOOSE(SUM(F1:F9),H1,H2,H3,H4,H5,H6,H7,H8,H9)

    This will lookup the value in F1:F9 and return the corresponding values from
    H1:H9.

    HTH

    Steve

  12. #12
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Surely it's just another Substitute statement. ??

    =SUBSTITUTE(SUBSTITUTE(CONCATENATE(TEXT(A1,"hh:mm Am/pm")&" - ",TEXT(B1,"hh:mm AM/PM")),"PM",""),"AM","")

    VBA Noob

  13. #13
    Forum Contributor kraljb's Avatar
    Join Date
    05-26-2004
    Location
    Illinois
    MS-Off Ver
    2007 (recent change)
    Posts
    256
    Try...

    =LEFT(TEXT(A1,"hh:mm AM/PM"),5)&" - "&LEFT(TEXT(B1,"hh:mm AM/PM"),5)

    Hope that helps,
    John

  14. #14
    Valued Forum Contributor
    Join Date
    03-25-2004
    Location
    Boston, MA US
    Posts
    1,094
    VBA Noob,

    Absolutely! Would have saved me a lot of typing had I not just glanced at your post.


    Regards,

    Steve

  15. #15
    Registered User
    Join Date
    08-24-2006
    Posts
    48
    Thank you all again so much!

    VBANoob:

    Your code is the shortest and works the best!

    =SUBSTITUTE(SUBSTITUTE(CONCATENATE(TEXT(A1,"hh:mm Am/pm")&" - ",TEXT(B1,"hh:mm AM/PM")),"PM",""),"AM","")

    Works perfectly!

    You rock! You all rock!

    See you next time.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1