+ Reply to Thread
Results 1 to 5 of 5

Comparing time and date values

  1. #1
    Registered User
    Join Date
    09-28-2020
    Location
    Wales
    MS-Off Ver
    office 2010
    Posts
    4

    Post Comparing time and date values

    Trying to identify rows where there is a 2 hour or greater difference between the time and date in cols A&B and that of cols C&D

    A simple No is required in col E where there is not a 2 hour or greater time difference.
    A simple Yes is required in col E where there is a 2 hour or greater time difference.

    Have manually populated col E with a few examples.

    Thanks for any ideas you have.
    Attached Files Attached Files

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Comparing time and date values

    Hi, I suggest you use a timestamp or create it
    That way you can do a simple IF for a time difference greater or equal to 2 hours
    You've got a time column and date for one and another for the other time and date
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: Comparing time and date values

    Assuming I understand correctly:

    1) Combine date and time into a single date/time serial number. A1+B1, C1+D1
    2) subtract the two date/time numbers (absolute value to avoid sign issues) ABS((A1+B1)-(C1+D1))
    3) see if it is larger than 1/12 of a day (2 hours/24 hours/day) =ABS(...)>CONVERT(2,"hr","day")
    4) This will put FALSE where the difference is less than or equal to 2 hours, and a TRUE where the difference is greater than 2 hours. To change to "yes"/"no", use an IF() function =IF(ABS(...)>CONVERT(...),"YES","NO")

    I notice that this puts "no" in E3 (difference appears to be about 1.5 hours), but you have marked this one as "yes". Is this a mistake in your example, or did I misunderstand something?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    09-28-2020
    Location
    Wales
    MS-Off Ver
    office 2010
    Posts
    4

    Re: Comparing time and date values

    MrShorty, followed those steps and it worked perfectly!! The E3 entry was my mistake.
    Thanks so much, added to your reputation.

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Comparing time and date values

    don't forget to mark the post as SOLVED

+ 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. Comparing Time Values
    By rjj920 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-25-2021, 09:57 AM
  2. [SOLVED] Comparing time values in 2 different sheets
    By PrestonT in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-15-2016, 04:59 PM
  3. [SOLVED] Issue with date format when comparing two date values (I'm in Australia)
    By aaron.irvine in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2013, 01:13 AM
  4. Comparing two time values in excel
    By Devika Gambhir in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-23-2013, 10:33 AM
  5. TAT calculation for comparing different Date/Time
    By llnoe50 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-29-2013, 11:58 AM
  6. comparing the time portion of a date/time
    By syphlix in forum Excel General
    Replies: 8
    Last Post: 03-25-2011, 04:08 AM
  7. Error when comparing time values
    By cas8100 in forum Excel General
    Replies: 6
    Last Post: 12-07-2009, 12:41 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