+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: Formula to compare and amend date and time

  1. #1
    Registered User
    Join Date
    05-11-2010
    Location
    Boston, UK
    MS-Off Ver
    Excel 2003
    Posts
    12

    Formula to compare and amend date and time

    This might not be very complicated for the Excel Gurus out there, but I have run out of ideas.

    I have an Excel spreadsheet with the following information

    Column D: Appointment Date
    Column E: Appointment Time
    Column F: Completion Date
    Column G: Completion Time
    Column H: Status

    What I am trying to do is to create a formula to determine if Date and time in F & G are within a 3 hour window of date and time in D & E. If the date/time is outside that window indicate in column H whether it is early or late.

    Please note that there is existing data in the tables and the data in columns are entered as numbers only and not formatted as time or date.

    I would really appreciate if someone can help me with this. I spent whole day yesterday on this with no luck.

    Many Thanks!
    Last edited by Saajan; 05-11-2010 at 06:44 AM.

  2. #2
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,252

    Re: Complicated Excel Formula

    Try this

    =IF(A2+B2>C2+D2+"03:00","Early",IF(A2+B2<C2+D2-"03:00","Late","On time"))

  3. #3
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,252

    Re: Complicated Excel Formula

    Quote Originally Posted by Saajan View Post
    Please note that there is existing data in the tables and the data in columns are entered as numbers only and not formatted as time or date.
    Just noticed this bit. Can you elaborate, maybe with examples?

  4. #4
    Registered User
    Join Date
    05-11-2010
    Location
    Boston, UK
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Formula to compare and amend date and time

    Quote Originally Posted by Bob Phillips View Post
    Just noticed this bit. Can you elaborate, maybe with examples?
    Thanks for your quick reply.

    The date fields are entered in the right format, meaning dd/mm/yyyy. But the time fields are entered as general 1030, 915, etc. When I try changing this field to Time format, it just resets it to 00:00:00. I hope this provides a better understanding of the problem.

    Your time and efforts are very much appreciated!
    Last edited by Saajan; 05-11-2010 at 07:01 AM.

  5. #5
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Formula to compare and amend date and time

    Quote Originally Posted by Saajan View Post
    The date fields are entered in the right format, meaning dd/mm/yy. But the time fields are entered as general 1030, 915, etc.
    You can generate the datetime values c/o the below construct:

    datetime 1
    D2+TEXT(E2,"00\:00")

    datetime 2
    F2+TEXT(G2,"00\:00")

  6. #6
    Registered User
    Join Date
    05-11-2010
    Location
    Boston, UK
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Formula to compare and amend date and time

    Lke mentioned earlier, not all time fields are entered as 4 digits.. Some are entered as 915, 230, etc.

    For Bob Phillips formula to work, I thought it was essential for the time and date to be in the correct format.

    Thanks!
    Last edited by Saajan; 05-11-2010 at 07:17 AM.

  7. #7
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Formula to compare and amend date and time

    Perhaps try the suggestion ?

    It is assumed for PM times you would be entering as 1430 rather than 230 (else you have no means of distinguishing between am/pm)

  8. #8
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,252

    Re: Formula to compare and amend date and time

    Quote Originally Posted by Saajan View Post
    Thanks for your quick reply.

    The date fields are entered in the right format, meaning dd/mm/yyyy. But the time fields are entered as general 1030, 915, etc. When I try changing this field to Time format, it just resets it to 00:00:00. I hope this provides a better understanding of the problem.

    Your time and efforts are very much appreciated!
    Then try

    =IF(A2+TEXT(B2,"00\:00")>C2+TEXT(D2,"00\:00")+"03:00","Early",IF(A2+TEXT(B2,"00\:00")<C2+TEXT(D2,"00 \:00")-"03:00","Late","On time"))

  9. #9
    Registered User
    Join Date
    05-11-2010
    Location
    Boston, UK
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Formula to compare and amend date and time

    May be I am doing it wrong... I highlight the 'H' column and insert the formula in the "fx" field and click on the green tick. Get the error "A value used in the formula is of the wrong data type."

    Am I Missing something here?

  10. #10
    Registered User
    Join Date
    05-11-2010
    Location
    Boston, UK
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Formula to compare and amend date and time

    Quote Originally Posted by Bob Phillips View Post
    Then try

    =IF(A2+TEXT(B2,"00\:00")>C2+TEXT(D2,"00\:00")+"03:00","Early",IF(A2+TEXT(B2,"00\:00")<C2+TEXT(D2,"00 \:00")-"03:00","Late","On time"))
    Really appreciate this!

    But do I need to change anything in the above formula?

    I would really appreciate if you could make it as simple as you can for me. I have mentioned in my first post which column referes to what.

    Many Thanks!

  11. #11
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,252

    Re: Formula to compare and amend date and time

    Try this

    =IF(D2+TEXT(E2,"00\:00")>F2+TEXT(G2,"00\:00")+"03:00","Early",IF(D2+TEXT(E2,"00\:00")<F2+TEXT(G2,"00 \:00")-"03:00","Late","On time"))

  12. #12
    Registered User
    Join Date
    05-11-2010
    Location
    Boston, UK
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Formula to compare and amend date and time

    Quote Originally Posted by Bob Phillips View Post
    Try this

    =IF(D2+TEXT(E2,"00\:00")>F2+TEXT(G2,"00\:00")+"03:00","Early",IF(D2+TEXT(E2,"00\:00")<F2+TEXT(G2,"00 \:00")-"03:00","Late","On time"))
    Thank you very much for that. It looks much better now.

    I think we are nearly there. The only problem is that if the work is completed on the same day at an earlier time, it still displays it as "On Time" whereas if it is completed on an earlier date, it is displayed correctly. It is only checked against date and not time. Also, if the work is completed on time, I need this to be left blank. I only need "Early" or "Late" indicated.

    Many Thanks.. You have been a great help!

  13. #13
    Registered User
    Join Date
    05-11-2010
    Location
    Boston, UK
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Formula to compare and amend date and time

    Any suggestions?

    Thanks!

  14. #14
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,252

    Re: Formula to compare and amend date and time

    Quote Originally Posted by Saajan View Post
    I think we are nearly there. The only problem is that if the work is completed on the same day at an earlier time, it still displays it as "On Time" whereas if it is completed on an earlier date, it is displayed correctly. It is only checked against date and not time.
    My understanding is that there is a 3 hour window, so if it is completed 3 hours earlier than the appointment time that is not Early, but if it 3 hours 1 minute earlier, then that is early. The formula does exactly that.

    Quote Originally Posted by Saajan View Post
    Also, if the work is completed on time, I need this to be left blank. I only need "Early" or "Late" indicated.
    Just delete the text -On Time- from the foirmula (but keep the quotes).

  15. #15
    Registered User
    Join Date
    05-11-2010
    Location
    Boston, UK
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Formula to compare and amend date and time

    Sorry.. I should have been more specific.

    Sometimes the work gets completed before the appointment time. Say for example, if the appointment time is 1400 on 15/05/2010 and the work gets completed at 1230 on the same day, then it should state as Early. But it is still showing up as "On Time".

    With regards to the above example:

    1359 = Early
    1400 = On Time
    1700 = On Time
    1701 = Late

    At present, it shows appointment time - 3hrs as early whereas it should show appointent time - 1 min as early.

    I hope it makes better sense now.

    Many Thanks for all your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0