+ Reply to Thread
Results 1 to 10 of 10

Subtracting Times with no space between time and AM/PM

  1. #1
    Registered User
    Join Date
    05-31-2012
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Subtracting Times with no space between time and AM/PM

    I have data that pulls into a spreadsheet with times that have no spaces between the time and the AM/PM. For example Time in: 9:10AM and Time out: 3:00PM. I want to subtract the 2 so that my actual hours are 5:50. Unfortunately, it won't work because there is no space between the time and the AM/PM. It works with a space if I use =TEXT(one - the other,"h:mm"). Unfortunately to get a space into all the 1000's of lines of data it would be extremely time consuming.

    Any suggestions?

    Thanks!

    MR

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Subtracting Times with no space between time and AM/PM

    With Start time in A1 and End time in B1

    in C1

    =MOD(SUBSTITUTE(SUBSTITUTE($B1,"AM"," AM"),"PM"," PM")-SUBSTITUTE(SUBSTITUTE($A1,"AM"," AM"),"PM"," PM"),1)

    to handle times over midnight.

    format C1 as "hh:mm"

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Subtracting Times with no space between time and AM/PM

    Try this
    Enter formula in C1
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Format cell C1 as Custom, h:mm
    v A B C
    1 9:10AM 3:00PM 5:50
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Subtracting Times with no space between time and AM/PM

    Here's another one, with the times in A2 and B2:

    =(LEFT(B2,LEN(B2)-2)+IF(RIGHT(B2,2)="PM",0.5,0) - (LEFT(A2,LEN(A2)-2)+IF(RIGHT(A2,2)="PM",0.5,0)))*24

    This returns the result in hours, but if you want hh:mm format just remove the *24 from the end.

    Hope this helps.

    Pete

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Subtracting Times with no space between time and AM/PM

    One way...

    Select the data in question
    Press the key combo of CTRL H (this will open the Find/Replace userform)

    Find what: A
    Replace with: [enter a space character]A
    Replace All

    Find what: P
    Replace with: [enter a space character]P
    Replace All

    That should convert the data to true time values that can then be calculated using simple formulas.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Subtracting Times with no space between time and AM/PM

    Here is a shorter version
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Subtracting Times with no space between time and AM/PM

    @Tony,
    Too easy .... !!!!

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Subtracting Times with no space between time and AM/PM

    Quote Originally Posted by JohnTopley View Post
    @Tony,
    Too easy .... !!!!
    Of course, this could be a PITA if the data is scattered all over the place!

  9. #9
    Forum Contributor
    Join Date
    12-18-2016
    Location
    London
    MS-Off Ver
    Microsoft 2013
    Posts
    145

    Re: Subtracting Times with no space between time and AM/PM

    To begin with, select the range of cells to look in. To search across the entire worksheet, click any cell on the active sheet.
    Open the Excel Find and Replace dialog by pressing the Ctrl + F shortcut. Alternatively, go to the Home tab > Editing group and click Find & Select > Find All.
    Now Find and Replace first A then P and adding the space for each of them.

  10. #10
    Registered User
    Join Date
    05-31-2012
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Subtracting Times with no space between time and AM/PM

    This was very helpful! Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Subtracting Times
    By Scootman1911 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-12-2015, 05:49 PM
  2. If a search term can be found 1 time, 2 times 3 times 4 times 5 times
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 09:57 PM
  3. Replies: 6
    Last Post: 06-21-2012, 12:32 PM
  4. subtracting a time from a range of times
    By coatey1 in forum Excel - New Users/Basics
    Replies: 9
    Last Post: 04-24-2010, 03:49 AM
  5. Replies: 4
    Last Post: 01-25-2009, 11:25 AM
  6. Subtracting times
    By gaftalik in forum Excel General
    Replies: 3
    Last Post: 11-02-2005, 02:45 PM
  7. Subtracting Times
    By bhalchandra2000 in forum Tips and Tutorials
    Replies: 1
    Last Post: 08-23-2005, 12:08 PM

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