|
-
May 17th, 2001, 08:11 AM
#1
Thread Starter
New Member
Subtracting and adding Time
I have setup a form to input a start time and finish time, but I need the values to remain in that format as supposed to 16:45 = 16:75. Could anyone please please tell me how I would subtract, for example, 08:45 from 16:15 to make 07:30!!
Read it a few times and you'll see what I mean!
-
May 17th, 2001, 08:36 AM
#2
Frenzied Member
This should work, the problem is, I don't know the correct interval code.
Code:
<%
StartTime = TimeValue("08:15")
EndTime = TimeValue("16:45")
TimeDiff = DateDiff("h", StartTime, EndTime)
Response.Write(TimeDiff)
%>
This will return 8. I've tried h:mm and just m, but I can't return 7:30.
Play around with it and see what you can do.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
May 17th, 2001, 08:48 AM
#3
Lively Member
You can also do like this:
Code:
oldTime = Format("16:15", "hh:mm")
newTime = DateAdd("h", -8, oldTime)
newTime = DateAdd("n", -45, newTime)
MsgBox "If you substract 8h & 45m from 16:15 you get: " & Format(newTime, "hh:mm")
This gives you "07:30".
Note that "format" only works in VB not in ASP. An ASP ex. is:
Code:
<%
oldTime = "16:15"
newTime = DateAdd("h", -8, oldTime)
newTime = DateAdd("n", -45, newTime)
Response.Write("If you substract 8h & 45m from 16:15 you get: " &newTime)
%>
You can control the time format with "session.lcid" in ASP.
________________________
Fredrik Klarqvist
-
May 17th, 2001, 08:59 AM
#4
Frenzied Member
D'oh. That's it. N is minutes because M is month.
Anyway, there should be a way to use DateDiff with "h:nn", but I can't get it to work.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|