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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function datediff related to diff times 1

Status
Not open for further replies.

vttech

Technical User
Jan 28, 2006
297
US
When I use the function datediff

Code:
=DateDiff("h",[txtLogIn],[txtLogOut])

I works great an I get the difference in hours between the two times
When I do

Code:
=DateDiff("hn",[txtLogIn],[txtLogOut])

I get #error in the textbox

I am trying to get a result like 8.15 which would mean an 8 hour and 15 minutes time difference between the two times.

What am I forgetting??


Newbie in search of knowledge
 
Datediff(): Returns a Variant (Long) specifying the number of time intervals between two specified dates.

more specifically, long integers. I do not believe this function is capable of returning any decimal values.



~Melagan
______
"It's never too late to become what you might have been.
 
by the way...
Code:
=DateDiff("n", txtLogIN, txtLogOUT)/60



~Melagan
______
"It's never too late to become what you might have been.
 

= Format(txtLogIN - txtLogOUT, "hh.mm")

=DateDiff("n", txtLogIN, txtLogOUT)/60
returns the hours (integer portion) + the percentage of an hour that corresponds to the remaining amount of time (decimal part)
 
Right... so a return of "8.25" means 8 hours, 15 minutes, or 8 1/4 hours.

Thats a great method for the other increment though, Jerry - nicely done.

~Melagan
______
"It's never too late to become what you might have been.
 
However: since his controls are named "txtLogIn", "txtLogOut", I'm afraid these fields may be definted as text and not date/time. For some reason, the DateDiff() function picks up the conversion but Format() does not... I got error on the Format() when the fields are defined as text but got correct results using DateDiff()

~Melagan
______
"It's never too late to become what you might have been.
 

Well, if we store numeric data as text type then we do have to play with conversions.....
 
Melagan, that is probably because VBA recognises the string as a date so it can work with DateDiff, however Format normally requires a non-string datatype and a pattern indicating how to format it.


Hope this helps.

[vampire][bat]
 
= Format(cdate(txtLogIN) - cdate(txtLogOUT), "hh.mm")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top