'If Date = Date' not working? (1 Viewer)

303factory

Registered User.
Local time
Today, 09:55
Joined
Oct 10, 2008
Messages
136
Hi people

I've got a bit of a headscratcher

I'm trying to loop backwards through time in 15 minute slots until I match a variable. However the my code doesn't seem to recognise my date variable as 'equal' when it is!

I.e. I step through and when I get to the line:

Code:
If t = firstAppointment Then

If I hover the mouse over 't' and 'firstAppointment', they both have exactly the same value as '12/11/2012 14:30:00', but it does not enter the If statement and my code behaves as if they were not equal, either I'm doing this wrong or I've broken maths

Code:
' t, sessionStart, firstSlot, firstAppointment are all Date variables
' slotlength is an integer 

    firstSlotFound = False

    t = sessionStart

    Do While firstSlotFound = False

        If t = firstAppointment Then

            firstSlot = t
            firstSlotFound = True

        End If

        t = t - TimeSerial(0, slotLength, 0)

    Loop

Can anyone advise what I'm doing wrong?

Thanks in advance
 

Brianwarnock

Retired
Local time
Today, 09:55
Joined
Jun 2, 2003
Messages
12,701
The comparison will be done on the underlying double decimal number for the date time which will run to many decimal places, the safe way to do date/time comparisons is with date functions, use Datediff and check for 0.

Brian
 

303factory

Registered User.
Local time
Today, 09:55
Joined
Oct 10, 2008
Messages
136
Ah I see, thank you kindly good sir!

and +1 on your sig
 

Brianwarnock

Retired
Local time
Today, 09:55
Joined
Jun 2, 2003
Messages
12,701
From my favourate poem, it sums up how I feel about life.

Brian
 

Users who are viewing this thread

Top Bottom