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

Calculate time + time ?

Status
Not open for further replies.

desprits

Programmer
Feb 14, 2004
40
CA
What should I do to calculate time if my variable are in a string format ?
Exemple :
00:30
00:14
00:08
02:24
12:51
00:14
------
?????

My code is :
TotalTemps = TotalTemps + Val(adoTriTemps.Recordset!Temps)

TotalTemps Type = Variante
Temps Type = Texte
 
desprits,

I think the TimeValue() function is what you need.

Check out the doco.

Cheers.

"Life is full of learning, and then there is wisdom"
 
This not working, it's cause an error -> Type mismatch ?

TotalTemps = TimeValue(TotalTemps) + TimeValue(adoTriTemps.Recordset!Temps)

TotalTemps TYPE = string
adoTriTemps.Recordset!Temps TYPE = string
 
dim TotalTemps as date

TotalTemps = TotalTemps + TimeValue(adoTriTemps.Recordset!Temps)

Check out thread222-780310 for info on rounding problems...
 
This don't working so ! :-(
ERROR --- > Type mismatch !
 
debug.print adoTriTemps.Recordset!Temps and you'll see why it doesn't work

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
test = (Format(TotalTempsUtilisation, "0.00000000") + Format(adoTriTemps.Recordset!TempsUtilisation, "0.00000000"))

This don't additionate !?
 
Then try to debug.printinate the values from the recordset.

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
desprits:
in
test = (Format(TotalTempsUtilisation, "0.00000000") + Format(adoTriTemps.Recordset!TempsUtilisation, "0.00000000"))
you are again trying to add to strings.
What you want to do is add date- or numeric values.
 
desprits:

1) The data item "Temps" in the DBMS record set must have a data type of either "Text" (and the data contained in that item must be of the correct format (eg 10:25pm)) OR it must be of type Date/Time.

2) Given that the above is true, then the code as jel wrote will work correctly:

dim TotalTemps as date

TotalTemps = TotalTemps + TimeValue(adoTriTemps.Recordset!Temps)


"Life is full of learning, and then there is wisdom"
 
I juste want to add time .. accumulate time !

Exemple :
00:23
00:11
01:51
------
?????

I would like that the routine give me --> 2:25
 
Then do this:
TotalTemps = TimeValue("00:23") + TimeValue("00:11") + TimeValue("01:51")
MsgBox TotalTemps

If you were to check, you would see that adoTriTemps.Recordset!Temps is returning something that is not a valid time.

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top