Computing.Net > Forums > Programming > Time subtraction

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Time subtraction

Reply to Message Icon

Name: Chipcom
Date: April 2, 2007 at 11:15:09 Pacific
OS: XP SP2
CPU/Ram: 2GhZ
Product: Intel
Comment:

Hi

I need know how to subtract times:

[TimeVar]=Time1-Time2

10:03:00=18:03:00-8:00:00

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 2, 2007 at 11:31:27 Pacific
Reply:

Depands on the language. There are tons of free TIME libraries for c/c++


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: cup
Date: April 2, 2007 at 11:33:07 Pacific
Reply:

Multiply them out into seconds, subtract them then divide them back.

18:03:00 = (18 * 60 + 3) * 60 + 0 = 64980
8:00:00 = (8 * 60 + 0) * 60 + 0 = 28800

64980 - 28800 = 36100
37800 / 3600 = 10 r 180 = 10 hours
180 / 60 = 3 r 0 = 3 minutes, 0 seconds


0

Response Number 3
Name: Chipcom
Date: April 2, 2007 at 11:38:40 Pacific
Reply:

Hi

I am talking about Access VBA.
Is there any function that can sabtract between two time variants and returns time result.


0

Response Number 4
Name: cup
Date: April 3, 2007 at 12:29:52 Pacific
Reply:

Don't know about access VBA but it is very similar to VBScript. This is how I would do it in VBScript. You can stick the following into a .wsf file and run it from the command line.

<job>
<script language="vbscript">
dim t1, t2, dayfrac, h, m, s
t1 = #18:03:00#
t2 = #8:00:00#
dayfrac = t1 - t2
s = clng(dayfrac * 86400)
h = s \ 3600
s = s mod 3600
m = s \ 60
s = s mod 60
' Do this instead of format date in case we get 24:00:00.
WScript.echo right(cstr(h+100),2) & ":" & right(cstr(m+100),2) & ":" & right(cstr(s+100),2)
</script>
</job>


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Batch file nested FOR loo... Batch loop with counter



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Time subtraction

VB6 add/subtract current time www.computing.net/answers/programming/vb6-addsubtract-current-time/8127.html

check file time creation www.computing.net/answers/programming/check-file-time-creation/10438.html

Date and time in VB www.computing.net/answers/programming/date-and-time-in-vb/9009.html