How to compare time portion of datetime field in access 97? RRS feed

  • Question

  • Hi,

    I have an employee report that shows the start (time and date) and end for the day, for each employee. I want to change the font color if the employee clocks out 15 minutes later (at lunch) to red but this below does not work:

    if Me.StopDateTime > #12:15 PM# then
    ME.StopDateTime.ForeColor =vbRed
    End If 

    I can change to color without checking the time so the problem is the time comparison. I read about time and date format and I also tried to compare to 0.51 (fractional for about 12:15pm) but it didn't work. It looks like I need to compare just the portion of the time of StopDateTime and I can not find a way to do so. Could someone point me in the right direction please.


    Friday, January 31, 2014 10:59 PM


  • You could use

        If Hour(Me.StopDateTime) = 12 And Minute(Me.StopDateTime) > 15 Or _
                Hour(Me.StopDateTime) > 12 Then


        If Me.StopDateTime - Int(Me.StopDateTime) > #12:15 PM# Then

    Regards, Hans Vogelaar (

    • Marked as answer by DSP1024 Monday, February 3, 2014 5:12 PM
    Saturday, February 1, 2014 12:49 PM