Solved

dtp value

Posted on 2004-10-12
9
183 Views
Last Modified: 2010-05-02
I've got a date time picker control array.
When I run my app, (0) is set by default as 12:00 AM and (1) as 1:00 AM
But if I step through my code,
(0) contains the value of 11/30/1999 while (1) contains 1:00 AM as expected.

Any clue as to why?
0
Comment
Question by:sirbounty
  • 5
  • 2
9 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 12288345
Is the .Format property set to dtpTime?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12288385
Nope - they're both custom.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12288399
Sorry - to clarify that custom format:

hh:mm tt
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12288637
If you convert the value returned by the dtp to a double, with CDbl(yourdtpvalue), is it an integer number or is it divisible by 86400?  

There are 86400 seconds in a day and this can cause problems:

    0 seconds = the exact date
 1.0 days = an exact date
    1 second = 12:01:00AM

(I'm not explaining myself too well here, am I)

Try calculating the following:

    CDate (yourdtpvalue - Int(yourdtpvalue))

Does this return the correct times?

J.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12288786
debug.? CDate (dtpTime(0)- Int(dtpTime(0)))
returns
12:00:00 AM

as expected.

Right now, my workaround is:

dtpTime(0) = TimeValue(dtpTime(0))

Although I'd like to know why I need this only on the first element...
0
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 250 total points
ID: 12296609
12AM is always going to be an issue -- it all comes down to how VB processes dates:

Imagine every day represented as a number (take, for example, today is 5 -- it's not, but let's pretend)
Now each hour in that day is a fraction -- 1/24 (or 0.0416r) in this case.

Today = 5
Today, 1AM = 5.0416r
Today, 2AM = 5.083r
Today, 3AM = 5.125
etc...

Take Today, 2AM:  VB handles the 'whole number' part of these value (the 5) and says that _that_ is the date.  It then takes the 'decimal' part of the value (0.083r) and says that _that_ is the time.

In your case, VB is trying to give you a date/time variable from the value of 12AM.  The problem is, that as 12AM is the 0th hour of the day, the 'decimal' part that it's using to give you the time is 0.0.

0.0 is the same as 0, so when you are converting to date/time form, it is taking that 0 and saying that this value is a 'whole number', so this date/time is a 'whole date'.

When you ask VB to print 5.0000, it prints 5.  Likewise, when you ask it to print 12/05/2004 00:00:00, it prints 12/05/2004.

You may ask, why are you getting this effect when you are only trying to deal with time.

The answer is its a caveate of a by-design feature.  The handling of time only assumes a date 'value' of 0 -- if you do

     Print CDate(0)

you will get the earliest date that your computer can handle (mine returns 31/12/1899).  If you do

     Print CDate(0.041666666)

you will get the earliest date your computer can handle + 1hr (mine returns 31/12/1899 01:00:00).

Your workaround

     dtpTime(0) = TimeValue(dtpTime(0))

is the correct way of disregarding dates when dealing with date/time values.  You should do this every time you handle a dtp value.

HTH

J.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12346817
Thanx for the explanation.  Now, for clarification, although redundant - should I also set the ending time to be Timevalue(dtpTime(1))??
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12567066
Sorry for the delay...I was hoping I'd get a response on my last clarification question, but oh well...
Thanx for your help.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 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