Date time problem

ylp

Registered User.
Local time
Today, 07:07
Joined
Mar 25, 2010
Messages
42
Hi,
I have a dtFirst is 2/28/2010 8:00:00 AM, dtSec 3/1/2010, and need to do :

3/1/2010 12:00:00 AM -2/28/2010 8:00:00 AM.

Tried
1. CDate(dtSec & " " & " 12:00:00 AM"), but still get 3/1/2010
2.DateDiff("h",2/28/2010 8:00:00 AM, 3/1/2010 12:00:00 AM), got an error: Comple error: Expected: list separator or )

Please help, thanks
 
I think you’ll find 12:00:00 AM has a value of zero.
 
And if you use actual dates you need # around them:

DateDiff("h",#2/28/2010 8:00:00 AM#, #3/1/2010 12:00:00 AM#)
 
Yes, YOU are right, need #, and it works!

Many thanks!
 
Sorry, but how to do that use variables?

I mean, DateDiff("h",#dtFirst#, #dtSec#), got compile error: expected: expression.
 
Sorry, but how to do that use variables?

I mean, DateDiff("h",#dtFirst#, #dtSec#), got compile error: expected: expression.

If the variables have been declared as DATE then you do not need them.

So, like:

Dim dtFirst As Date
Dim dtSec As Date

dtFirst = Me.YourTextBoxName
dtSec = Me.YourSecondOne

Something = DateDiff("h", dtFirst, dtSec)
 

Users who are viewing this thread

Back
Top Bottom