Solved

Why are there milliseconds in vb6 Date data type

Posted on 2008-10-31
23
1,847 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:d3n
  • 8
  • 7
  • 3
  • +1
23 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 22849909
Hello d3n,

Please post the code that is producing the errors.

Regards,

Patrick
0
 
LVL 1

Author Comment

by:d3n
ID: 22850033
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

Open in new window

print2.jpg
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 22850264
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
0
 
LVL 1

Author Comment

by:d3n
ID: 22850659
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.


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

Open in new window

0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 0 total points
ID: 22851075
Hm.  I cannot replicate that behavior.

Of course, why would you calculate dDateTime this way, when you could just do this:

dDateTime = dDate + dTime         ?

Also, what if you try:

dDateTime = CDate(Format(dDate, "yyyy-mm-dd") & " " & Format(dTime, "hh:nn:ss"))
0
 
LVL 1

Author Comment

by:d3n
ID: 22851425
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
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 22855061
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
0
 
LVL 45

Expert Comment

by:aikimark
ID: 22855652
Just for grins, please share the format settings for Date and Time values in the regional settings of either of these two PCs.
0
 
LVL 1

Author Comment

by:d3n
ID: 22856126
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
0
 
LVL 45

Expert Comment

by:aikimark
ID: 22856374
I see a language difference (Nederland vs. Netherlands)
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 22856640
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
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 22856702
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

0
 
LVL 45

Expert Comment

by:aikimark
ID: 22856947
@d3n

What happens on your PC when you change to Nederland ?
0
 
LVL 1

Author Comment

by:d3n
ID: 22865316
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.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 22865783
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?
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

Open in new window

0
 
LVL 1

Author Comment

by:d3n
ID: 22865929
I send the following code (compiled as exe) to the client with some instruction.
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

Open in new window

0
 
LVL 1

Author Comment

by:d3n
ID: 22868119
All,

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

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
ID: 22868196
What about the change from Nederland?
0
 
LVL 1

Author Comment

by:d3n
ID: 22868361
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.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 22868395
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?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 24345156
This question should be closed with points refunded.  Do not delete.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now