Results 1 to 4 of 4

Thread: Subtracting and adding Time

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Posts
    4

    Cool 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!

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    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.

  3. #3
    Lively Member
    Join Date
    May 2001
    Location
    Falkenberg, Sweden
    Posts
    76
    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

  4. #4
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    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
  •  



Click Here to Expand Forum to Full Width