hi
how can i making plus operation between two or three times like this :
00:00:25 + 00:00:15 + 00:01:00 = 00:01:40
please help
Printable View
hi
how can i making plus operation between two or three times like this :
00:00:25 + 00:00:15 + 00:01:00 = 00:01:40
please help
You can use this:
VB Code:
Option Explicit Private Sub Form_Load() Dim mytime mytime = TimeValue("00:00:25") + _ TimeValue("00:00:15") + TimeValue("00:01:00") Debug.Print Format(mytime, "h:m:s") End Sub
just another way if you already had them as dates. convert to a double then back to date
VB Code:
Dim d1 As Date, d2 As Date, d3 As Date d1 = CDate("00:00:25") d2 = CDate("00:00:15") d3 = CDate("00:01:00") MsgBox CDate(CDbl(d1) + CDbl(d2) + CDbl(d3))
casey.
Why DOUBLE and not INTEGER, or LONGWORD?Quote:
Originally Posted by vbasicgirl
DOUBLE is such an inaccurate datatype - I would be afraid to use it.
Quote:
Originally Posted by vbasicgirl
You probably could skip the conversion (per se) and do:
VB Code:
Option Explicit Private Sub Form_Load() MsgBox CDate("00:00:25") + CDate("00:00:15") + CDate("00:01:00") End Sub
Bruce.
David,
I took the liberty of optimising your example:
VB Code:
Dim mytime As Date mytime = CDate(TimeValue("00:00:25") + TimeValue("00:00:15") + TimeValue("00:01:00")) Debug.Print Format(mytime, "hh:mm:ss")
Bruce.
Bruce Fox - yes, you are right, thanks for that.
szlamany - i was always told that time is actually a double, where a day is 1 and time is a fraction of that (double).
have i been told wrong ?
thank you.
casey.
Where have you seen that reference?Quote:
Originally Posted by vbasicgirl
Whenever you convert anything to floating point, you end up with precision problems - since it's using logarithms to do the math and storing the values in an "exponential/mantisa" format.
I've seen all these posts about how to do this, but if I had my choice I would probably take the hours*60 to turn them into minutes, minutes and multiply by 60 to turn them into seconds - add all that up so that I'm dealing "seconds" only.
Then add all the values (seconds that is) together - and then format that "total number of seconds" back into a hr:mn:ss value.
From MSDN
http://msdn.microsoft.com/library/de...tedatatype.aspQuote:
Date data type
A data type used to store dates and times as a real number. Date variables are stored as 64-bit (8-byte) numbers. The value to the left of the decimal represents a date, and the value to the right of the decimal represents a time.
Bruce.
DATES are stored as DOUBLE - that's what that says.
It also says this:
That's for when a numeric type if converted to a DATE - that in no way indicates how the time is stored in the DOUBLE of the DATE FORMAT datatype!Quote:
When other numeric types are converted to Date, values to the left of the decimal represent date information while values to the right of the decimal represent time. Midnight is 0 and midday is 0.5. Negative whole numbers represent dates before 30 December 1899.
i just found this in my notes, i can see where i got it from. thanks for the info.
thank you.Quote:
A common question is what is the date or time right now? To answer that, VB has 3 functions available. The Date function returns the current date, the Time function returns the current time and the Now function returns the current time and date.
Actually, all three return time/date because all three return a variable of type Date. In previous versions of VB, there was no Date type. Instead, the functions returned a Double. Today, you can still treat the Date Type as if it were a double.
The Date type is an 8 byte double precision floating point number representing the number of days since midnight, Dec 30, 1899. The fractional part of the date represents the time in days. So 12 noon would be half a day, or 0.5.
For instance if the time/date now were Aug 8, 2002 6:00 PM, the values of the three functions would be:
Now() = 37476.75
Date() = 37476
Time() = 0.75
casey.
Thanks. I usually go back and optimize thinks when i have them working, but had to go out, so I posted with the *ugly* variant type. i was actually going to try to see how date worked, because I knew there was no TIME typeQuote:
Originally Posted by Bruce Fox
thanx guys , it works great
thanks again 2 all :thumb:
:eek2: :eek2: