this is the code which I found online and works great. I forgot its author but whoever you are, 10x but a lil help would be appreciated...
here is the code -
'public variables
-
Const MSecInSec As Double = 1000
-
Const SecsInMin As Double = 60
-
Const MinsInHour As Double = 60
-
Const HoursInDay As Double = 24
-
Const SecsInDay As Double = HoursInDay * MinsInHour * SecsInMin
-
Const mSecMult As Double = 1 / (SecsInDay * MSecInSec)
-
-
private sub command1_click()
-
-
msgbox ReturnTimeDifference("01:00:00:00","04:30:00:00")
-
msgbox ReturnTimeDifference("04:00:00:00","01:30:00:00")
-
-
-
end sub
-
-
-
Public Function ReturnTimeDifference(ByVal smalltime As String, ByVal bigtime As String) As String
-
Dim TimeA As Date
-
Dim TimeB As Date
-
Dim Res As Double
-
Dim timeparts As Variant
-
Dim timepartsb As Variant
-
Dim ms As String
-
Dim ms2 As String
-
timeparts = Split(smalltime, ":")
-
timepartsb = Split(bigtime, ":")
-
ms = timeparts(3)
-
ms2 = timepartsb(3)
-
-
ms = ms & String(3 - Len(ms), "0")
-
ms2 = ms2 & String(3 - Len(ms2), "0")
-
-
-
-
-
TimeA = TimeSerialEx(timeparts(0), timeparts(1), timeparts(2), ms) '01:04:12.2
-
TimeB = TimeSerialEx(timepartsb(0), timepartsb(1), timepartsb(2), ms2) '05:08:15.55
-
-
Res = Format$((TimeB - TimeA) * SecsInDay, "0.00") 'RETURNS POSITIVE NO MATTER WHAT!
-
-
ReturnTimeDifference = Format$(Res / SecsInDay, "hh:nn:ss:") & _
-
Round(Res - Fix(Res), 2) * 100 'avoids the decimal point
-
-
End Function
-
both return positive value. he had commented this line as "returns postive no matter what -
Res = Format$((TimeB - TimeA) * SecsInDay, "0.00") 'RETURNS POSITIVE NO MATTER WHAT!
-
but i can't seem to figure out which part of it makes Res positive always.
any tips?
5 2002
The format 0:00 makes it return only positive numbers since it doesn't allow for the negative sign.
i thot about it and removed it and tweaked it but nothing changed. can u help me out a lil bit?
I don't know the formats it allows. You may have to look that up but you can try 0:00;-0:00.
Hi
As pointed out by Rabbit the Time format does not take account of the sign and only returns +ve values.
However, contrary to the statement in the code this line - Res = Format$((TimeB - TimeA) * SecsInDay, "0.00")
does return -ve values, so the only suggestion I have is adding this line to the bottom of the function - If Res < 1 Then ReturnTimeDifference = "-" & ReturnTimeDifference
-
??
MTB
As JosAH has pointed out somewhere you may wish to research JD (for Julian day) where you can convert a date to JD then add (or subtract) the number of days and then convert the new JD back to date. This is simply done.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phil Powell |
last post by:
My first time working with a PHP class, and after 6 hours of working out the
kinks I am unable to return a value from the class, so now I appeal to the
general audience what on earth did I do wrong...
|
by: Koji Ishii |
last post by:
According to the doc, Stream.Read() returns:
- # of bytes read, or
- 0 for EOF
But could that be a negative value? If so, how should we program against
such case?
I have a loop like this:...
|
by: Angus Comber |
last post by:
Hello
Sorry this really is a newbie question!
I am doing some floating point arithmetic and calculating the time
difference between two dates. The date values being comparied are actually...
|
by: OutdoorGuy |
last post by:
Greetings,
I am attempting to compile the code below, but I am receiving an error
message when I do so. The error message is: "CSO161:
'Forloop.CalcAvg(int)': Not all code paths return a...
|
by: Bill Littman |
last post by:
We are using a DB2 7.2 system.
On the DB2 Control Center of a server, we are viewing the details of the
tablespaces. The "percentage used" column is showing a negative value(-69)
for one of the...
|
by: Peter |
last post by:
Hi
I am using DateTime class and TimeOfDay.Hours attribute to return current time. It returns right value on two servers, but in one particular server it does not return right time. I checked that...
|
by: Martin Wells |
last post by:
Plain char may be signed or unsigned. Typical ranges could be:
CHAR_MIN == -128, CHAR_MAX == 127
CHAR_MIN == 0, CHAR_MAX == 255
The Standard says that the behaviour is undefined if we...
|
by: mdeh |
last post by:
Hi Everyone,
Tried to post via Google..which once again seems to be fritzed...so
please excuse if 2 posts show up.
I am trying to understand why I am not getting a negative value back,
using my...
|
by: vikastcser |
last post by:
Hi All ,
I have a table where four rows are there and each row has two tds.one td is for label and two image icons and other td is used for keeping numeric values.
I am able to accomodate digits...
|
by: Pachalo |
last post by:
Morning...
Am working on a simple billing system and a looking for a code that can help calculate the difference in time between sessions..(am using VB.Net )
This is what is happening:
l...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |