|
-
Nov 14th, 2017, 11:52 AM
#1
Thread Starter
Junior Member
Getting wrong date ??
I have striped this code to the parts needed to demonstrate my problem.
Code:
Dim MyStartDay As Date
SELECT SchueckWkStart FROM DSWkNo where SchueckJobNo = '107 - 123456'
MyStartDay = CDate(SchueckWkStart)
This query returns a SchueckWkStart date as "2017-11-06", which is correct, but the "MyStartDay" variable will contain "2017-11-07", a day added immediately.
Can anyone explain why?
-
Nov 14th, 2017, 12:52 PM
#2
Re: Getting wrong date ??
It is just a guess since we don't know what database you are using, but dates are usually stored as a double precision number with the date represented as an offset by the whole number since January 1, 1900, and the time is the decimal portion as the number of seconds since midnight. The error you are seeing is probably due to a round off as the double precision number is converted to a whole number.
J.A. Coutts
-
Nov 14th, 2017, 02:37 PM
#3
Re: Getting wrong date ??
Good point couttsj.
Probably adding an Int() will then fix it.
MyDate = CDate(Int(WkStart))
-
Nov 15th, 2017, 12:10 PM
#4
Re: Getting wrong date ??
I don't think an integer will handle it in this case, as anything over 32767 will be interpreted as a negative number.
This is how a date is stored:
Debug.Print CDbl(CDate("11/15/2017 8:42:32 PM"))
43054.8628703704
This is how it is interpreted as a long:
Debug.Print CLng(CDate("11/15/2017 8:42:32 PM"))
43055
And this is what you get using Fix:
Debug.Print CLng(Fix(CDate("11/15/2017 8:42:32 PM")))
43054
J.A. Coutts
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|