Comparing dates with Time Stamps

J

June

I have two date fields. I have to determine if the date
in one of the fields falls either before or on the same
day as the other field. I was using the following logic:

If MySet![Exp Arrival] <> 0 And MySet![DueDate] > MySet!
[Exp Arrival] Then
MySet![OnTime] = 1
ElseIf MySet![Exp Arrival] = MySet![DueDate] Then MySet!
[OnTime] = 1
Else
MySet![OnTime] = 0

This worked fine before, however, the format of the data
that is being input into my database now has time stamped
information on it. If my duedate is 7/6/03 11:50 AM, and
my Exp Arrival is 7/6/03 12:01 PM, the above logic will
show that OnTime would be 0, when it should be 1. Is
there a way to work around this so I don't have to change
much code?
 
W

Wayne Morgan

Int(MySet![DueDate])

should return just the date portion. Date/Time is actually stored as a number. The time is
the decimal portion.
 
J

jfp

Int returns a 16 bit value -- you might need to convert it to a Long.
Not sure.
-=-=-=
 
D

Douglas J. Steele

I'm not sure Int does return an integer (i.e. a 16 bit value). What it does
is return the integer part of the value. The Help file doesn't say that it
converts it to an Integer.

If you're concerned, try using the DateValue function:

DateValue(MySet![DueDate])

--
Doug Steele, Microsoft Access MVP



jfp said:
Int returns a 16 bit value -- you might need to convert it to a Long.
Not sure.
-=-=-=
Wayne said:
Int(MySet![DueDate])

should return just the date portion. Date/Time is actually stored as a number. The time is
the decimal portion.
 
J

jfp

how interesting -- just another VB naming issue i suppose.
You are right -- Int() does NOT return an Int. Please do not confuse
with CInt() !!
For an argument of 65537.2 CInt() gave an overflow error but Int
returned 65537.
-=-=-=
 
J

June

Interesting...In my case, the Int(MySet![DueDate]) worked
just fine as I was comparing whether two dates were the
same (regardless of the time stamp). Thanks for all the
help guys!

June
-----Original Message-----
how interesting -- just another VB naming issue i suppose.
You are right -- Int() does NOT return an Int. Please do not confuse
with CInt() !!
For an argument of 65537.2 CInt() gave an overflow error but Int
returned 65537.
-=-=-=
Douglas said:
I'm not sure Int does return an integer (i.e. a 16 bit value). What it does
is return the integer part of the value. The Help file doesn't say that it
converts it to an Integer.

If you're concerned, try using the DateValue function:

DateValue(MySet![DueDate])

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top