d3n
asked on
Why are there milliseconds in vb6 Date data type
Some of my clients are getting type mismatch errors because the date data type includes milliseconds. although, I think it are milliseconds.
How on earth is it possible that the VB6 Date data type includes milliseconds?
See uploaded file (printscreen of current values of the Date-vars)
print1.jpg
How on earth is it possible that the VB6 Date data type includes milliseconds?
See uploaded file (printscreen of current values of the Date-vars)
print1.jpg
ASKER
When I run the attached code on my clients computer I get that strange result, see attached file.
Private Sub DateWithMilliSecs()
Dim dDateFrom As Date
MsgBox "DateFrom: " & dDateFrom, vbInformation
End Sub
print2.jpg
d3n,
I think the format you are seeing is dependent on your Windows regional settings, because I just ran the
code above and got:
DateFrom: 12:00:00 AM
In any event, you cannot rely on a VB6 / VBA Date value to have miliseconds done correctly. That level
of precision is just not there.
Now, please elaborate on the type mismatches you mentioned...
Regards,
Patrick
I think the format you are seeing is dependent on your Windows regional settings, because I just ran the
code above and got:
DateFrom: 12:00:00 AM
In any event, you cannot rely on a VB6 / VBA Date value to have miliseconds done correctly. That level
of precision is just not there.
Now, please elaborate on the type mismatches you mentioned...
Regards,
Patrick
ASKER
Thanks a lot for for your fast answers and excuse me for my poor description about the Type Mismatch error.
Strange thing is that there are two computers out of 200 which are having this problem and the regional settings are completely identical to my machine, my machine works fine
Check the attached code which is giving the Type Mismatch error on the clients machine.
Strange thing is that there are two computers out of 200 which are having this problem and the regional settings are completely identical to my machine, my machine works fine
Check the attached code which is giving the Type Mismatch error on the clients machine.
Private Sub DateWithMilliSecs()
Dim dDate As Date
Dim dTime As Date
Dim dDateTime As Date
'
'fill dDate and dTime with random value
dDate = CDate("2008-1-1")
dTime = CDate("12:00:00")
'
'following line (combining date and time in 1 var) results in
'Type Mismatch error because dTime has value {12:00:00 0}
dDateTime = CDate(dDate & " " & dTime)
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm known with the different ways of combining dates and times.
I don't get the Type Mismatch error when I format both variables, unfortunately it is no realistic option for us to append this fix in the entire application.
I'm wondering why the space and extra 0 is in the dTime variable (12:00:00 0) , I think it's very strange!
I hope you or someone else has any solution
Regards,
Dennis
I don't get the Type Mismatch error when I format both variables, unfortunately it is no realistic option for us to append this fix in the entire application.
I'm wondering why the space and extra 0 is in the dTime variable (12:00:00 0) , I think it's very strange!
I hope you or someone else has any solution
Regards,
Dennis
Date/Time values in Access are stored, in the physical table, as a Number of type Double ( a number with a decimal point). The value to the Left of the decimal point is the number of days since the base date of Dec 30, 1899. The value to the right of the decimal point (the fractional part of the number) represents the time, measured in SECONDS since midnight, as a Fraction of 1 day (= 86400 seconds).
The smallest accurate interval in Access is 1 second.
An Access date of 0.0 is displayed as 12/30/1899 12:00:00 AM
you cannot append Date parts and Time parts like this:
dDateTime = CDate(dDate & " " & dTime)
try it like this:
dDateTime = dDate + dTime (yes, you can add date objects using the + operator, because, internally, dates are really numbers in disguise, as explained above )
The Type Mismatch is due to the fact the date and time objects (dDate is dimmed as Date), cannot be treated as strings ( & " " & will try to concatenate three strings together, thus creating a new string which cannot then be converted into a Date object ("1/1/2008 12:00:00" is not a Date - it is a string, and the cDate function has no clue how that string should be converted into a date object.
AW
The smallest accurate interval in Access is 1 second.
An Access date of 0.0 is displayed as 12/30/1899 12:00:00 AM
you cannot append Date parts and Time parts like this:
dDateTime = CDate(dDate & " " & dTime)
try it like this:
dDateTime = dDate + dTime (yes, you can add date objects using the + operator, because, internally, dates are really numbers in disguise, as explained above )
The Type Mismatch is due to the fact the date and time objects (dDate is dimmed as Date), cannot be treated as strings ( & " " & will try to concatenate three strings together, thus creating a new string which cannot then be converted into a Date object ("1/1/2008 12:00:00" is not a Date - it is a string, and the cDate function has no clue how that string should be converted into a date object.
AW
Just for grins, please share the format settings for Date and Time values in the regional settings of either of these two PCs.
ASKER
Guys, thanks for you feedback, but again I know how to solve the Type Mismatch error and how to handle DateTimes etc..
Thing is the value of dTime, it has an extra zero which I can't explain!?
I attached two print screens of Regional Settings in Windows Registry.
print3-dj.jpg
print4-ds.jpg
Thing is the value of dTime, it has an extra zero which I can't explain!?
I attached two print screens of Regional Settings in Windows Registry.
print3-dj.jpg
print4-ds.jpg
I see a language difference (Nederland vs. Netherlands)
I have set my Regional settings to The Netherlands, and then executed your procedure
Private Sub DateWithMilliSecs()
Dim dDateFrom As Date
MsgBox "DateFrom: " & dDateFrom, vbInformation
End Sub
and I get this.
I have no idea where the extra 0 is coming from, but it is not Milliseconds in your case. It might be a representation of AM/PM. After using my advice about adding the Date part and the Time part, are you still getting the Type Mismatch? If yes, can you show us a screen shot of precisely what line of code is raising the error?
AW
NetherlandsDateTime.JPG
Private Sub DateWithMilliSecs()
Dim dDateFrom As Date
MsgBox "DateFrom: " & dDateFrom, vbInformation
End Sub
and I get this.
I have no idea where the extra 0 is coming from, but it is not Milliseconds in your case. It might be a representation of AM/PM. After using my advice about adding the Date part and the Time part, are you still getting the Type Mismatch? If yes, can you show us a screen shot of precisely what line of code is raising the error?
AW
NetherlandsDateTime.JPG
Actually, if I use you other version of DateTimeWithMilliSecs:
Private Sub DateWithMilliSecs()
Dim dDate As Date
Dim dTime As Date
Dim dDateTime As Date
'
'fill dDate and dTime with random value
dDate = CDate("2008-1-1")
dTime = CDate("12:00:00")
'
'following line (combining date and time in 1 var) results in
'Type Mismatch error because dTime has value {12:00:00 0}
dDateTime = CDate(dDate & " " & dTime)
End Sub
I do NOT get a type mismatch on the last line. There is something else going on in your code.
can you post the complete code, as the VBP, and associated files, that you are trying this in. We wnat to try to reproduce your problem, as completely as possible.
AW
Private Sub DateWithMilliSecs()
Dim dDate As Date
Dim dTime As Date
Dim dDateTime As Date
'
'fill dDate and dTime with random value
dDate = CDate("2008-1-1")
dTime = CDate("12:00:00")
'
'following line (combining date and time in 1 var) results in
'Type Mismatch error because dTime has value {12:00:00 0}
dDateTime = CDate(dDate & " " & dTime)
End Sub
I do NOT get a type mismatch on the last line. There is something else going on in your code.
can you post the complete code, as the VBP, and associated files, that you are trying this in. We wnat to try to reproduce your problem, as completely as possible.
AW
@d3n
What happens on your PC when you change to Nederland ?
What happens on your PC when you change to Nederland ?
ASKER
Indeed, the zero could be another representation of AM/PM, but where is it set in Windows?
I don't have to post my code because the problem is at the clients computer and it is happening immediately when the dTime-var is declared. Check the code-samples above.
Nederland is dutch for Netherlands.
I don't have to post my code because the problem is at the clients computer and it is happening immediately when the dTime-var is declared. Check the code-samples above.
Nederland is dutch for Netherlands.
I was observing a difference between your PC, without the problem, and your client's PC, with the problem. I understand that both languages/locations represent the same thing. However you may fairly easily change that setting on the client PC and retest your application to determine whether that is the cause or not.
============
What happens when you do the following on the client PC?
============
What happens when you do the following on the client PC?
1. Checking CDate() function
dDateTime = CDate("2008-1-1 12:00:00")
2. Checking date -> string -> date conversion
dDate = CDate("2008-1-1")
dTime = CDate("12:00:00")
dDateTime = dDate + dTime
ASKER
I send the following code (compiled as exe) to the client with some instruction.
Let's wait for the test.log file!
Let's wait for the test.log file!
Dim dDate As Date
Dim dTime As Date
Dim dDateTime As Date
'
Open App.Path & "\test.log" For Output As #1
Print #1, "Begin of test"
Print #1, "=========="
'
'1. Checking CDate() function
Print #1, "1. Checking CDate() function"
dDateTime = CDate("2008-1-1 12:00:00")
'
Print #1, "dDate: " & dDate
Print #1, "dTime: " & dTime
Print #1, "dDateTime: " & dDateTime
Print #1, " "
'
'2. Checking date -> string -> date conversion
Print #1, "2. Checking date -> string -> date conversion"
dDate = CDate("2008-1-1")
Print #1, "dDate: " & dDate
dTime = CDate("12:00:00")
Print #1, "dTime: " & dTime
dDateTime = dDate + dTime
Print #1, "dDateTime: " & dDateTime
'
Print #1, "=========="
Print #1, "End of test"
Close #1
ASKER
All,
See the test.log as an attached code snippet...
Regards, Dennis
See the test.log as an attached code snippet...
Regards, Dennis
Begin of test
==========
1. Checking CDate() function
dDate: 0:00:00 0
dTime: 0:00:00 0
dDateTime: 1-1-2008 12:00:00 0
2. Checking date -> string -> date conversion
dDate: 1-1-2008
dTime: 12:00:00 0
dDateTime: 1-1-2008 12:00:00 0
==========
End of test
What about the change from Nederland?
ASKER
Nederland is Dutch for Netherlands, my OS is English and the OS of the client is Dutch, that's why the sCountry-string has a different value. It cannot be changed that way.
Are any of your properly working clients using a Dutch version of Windows? If so, what do their registry settings look like for Regional/Language?
This question should be closed with points refunded. Do not delete.
Please post the code that is producing the errors.
Regards,
Patrick