Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff Function

Status
Not open for further replies.

Larry8696

Technical User
Dec 28, 2006
9
US
Hello,

I am using this function in a query to show the difference between 2 times in minutes, the results returned do not make sense.

Sample DateDiff("n", Date1, Date2)

Date1 = 6:00 P.M.
Date2 = 6:01 P.M.

Result comes back as an 8 digit number 5629041

Thanks in advance
 
Code:
DateDiff("n", #6:00pm#, #6:01pm#)
returns a 1

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Date1 = 6:00 P.M.
Date2 = 6:01 P.M. ?
How about:

Dim datStart As Date
Dim datEnd As Date
datStart = #1/11/2007 18:00:00#
datEnd = #1/11/2007 18:01:00#

Then.....
yourVariable = DateDiff("n", datStart, datEnd)





Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.
 
Gosh it works for me.
Dont you hate that!

This expression gives me the value 1 as we might expect.
Code:
SELECT DateDiff("n",#6:00:00 PM#,#6:01:00 PM#)

This expression gives me the expected number of minutes where the columns are Date/Time data types.
Code:
SELECT DateDiff("n", opendate, lastchange)

How are you assigning values to your date fields?
What are their data types?
 
Both data types date/time fields, I have to check, I have
the field set by an event and I think I used now() to set
the time. Would this be where the error is.
 
Could you copy and paste the queries used to insert or update the date fields and to retrieve the number of minutes. I emphasize copy and paste, cause if you type the queries there is always the risk of an new error which will distract us from the real problem.

Also use the TGML code tags around your code. (The TGML tags are descibed below your message after you click Preview Post.)

The source of the problem is either the code or the data. If your code matches that posted here, then take a close look at the data that is giving you the unexpected results.
 
Thanks everone,

I found the error, I used 2 different set values one
was now() and the other was date(), since I changed them both to now(), everything works fine.

Larry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top