+ Reply to Thread
Results 1 to 6 of 6

Conditional formula based on if a cell is hh:mm:ss or mm:ss

  1. #1
    Registered User
    Join Date
    06-05-2020
    Location
    Sydney Australia
    MS-Off Ver
    Office 365
    Posts
    3

    Question Conditional formula based on if a cell is hh:mm:ss or mm:ss

    Hi good people

    I am needing some assistance writing a formula that can calculate a cell that may appear in either hh:mm:ss or mm:ss format to the correct number of seconds.

    I am aware that using the formula =A1*1440 will give the correct number of seconds if cell A1 contains an entry that in the format mm:ss
    but if cell A1 contains a value in the format hh:mm:ss then the incorrect value is displayed and the correct formula =A1*86400 should be used.

    For example (Please note cell A1 is formatted as Text)

    Cell A1 = 40:10 =A1*1440 = 21410 seconds (Correct)
    Cell A1 = 00:27 =A1*1440 = 27 seconds (Correct)
    Cell A1 = 1:20:35 =A1*1440 = 80.583 seconds (Incorrect)
    Cell A1 = 1:20:35 =A1*86400 = 4835 seconds (Correct)

    Is there a formula that can be written which can take into account the difference time formats?

    Any help would be appreciated.

    Thanks
    Steve

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,659

    Re: Conditional formula based on if a cell is hh:mm:ss or mm:ss

    The important thing is: what is the underlying value of the cell?
    Do the simple test:
    type in cell A1: 01:20:35 formatted as "hh:mm:ss"
    In cell A2 = A1, formatted as general = 0.055961
    Try to change format of A1 as "mm:ss" or "ss"
    what is its underlying value displaying in A2? Not change.

    So, convert to hour (*24), minute(*1440), second(*86400) regardless to cell format
    Quang PT

  3. #3
    Registered User
    Join Date
    06-05-2020
    Location
    Sydney Australia
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Conditional formula based on if a cell is hh:mm:ss or mm:ss

    Hi Quang.
    Thanks for your reply.

    As mentioned above, cell A1 and all other cells that contain time are formatted as text.

    So the underlining value is exactly as whats shown.

    Any more ideas?

    Steve

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,659

    Re: Conditional formula based on if a cell is hh:mm:ss or mm:ss

    Try to convert text to "hh:mm:ss" first by:
    RIGHT(IF(LEN(A1)>5,"00:0","00:")&A1,8)
    Then convert to second by time 86400
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-05-2020
    Location
    Sydney Australia
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Conditional formula based on if a cell is hh:mm:ss or mm:ss

    Thats works perfectly.
    Thanks for your help..

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,165

    Re: Conditional formula based on if a cell is hh:mm:ss or mm:ss

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ 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. [SOLVED] Conditional Formatting formula to color one cell based on a date range in another cell
    By katiedee1625 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-27-2018, 08:52 AM
  2. Replies: 1
    Last Post: 03-06-2014, 07:14 PM
  3. [SOLVED] Conditional format a cell based on a result of a formula in another cell
    By Taiter in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-20-2013, 04:45 PM
  4. Replies: 1
    Last Post: 03-11-2013, 03:10 PM
  5. Replies: 1
    Last Post: 03-10-2013, 01:54 PM
  6. Replies: 2
    Last Post: 06-22-2012, 08:51 AM
  7. Replies: 3
    Last Post: 05-25-2012, 03:30 PM

Tags for this Thread

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