DateAdd

Discussion in 'ASP General' started by Wer, Jan 31, 2005.

  1. Wer

    Wer Guest

    Hi,

    I'm trying to add hours together in the format HH:MM + HH:MM. There
    doesn't seem to be a functional part of DateAdd that will accomplish
    this though ?

    The calculation is to work out how many hours have been spent on a
    website so exceeding the 24:00 is fine.
    Is there another function that would accomplish this ?

    Thanks

    W.
    Wer, Jan 31, 2005
    #1
    1. Advertising

  2. Wer wrote:
    > Hi,
    >
    > I'm trying to add hours together in the format HH:MM + HH:MM. There
    > doesn't seem to be a functional part of DateAdd that will accomplish
    > this though ?
    >
    > The calculation is to work out how many hours have been spent on a
    > website so exceeding the 24:00 is fine.
    > Is there another function that would accomplish this ?
    >
    > Thanks
    >
    > W.

    Use DATEPART to convert the datetime values to the appropriate resolution
    and simply add them together arithmetically. You will need to create a
    function to display the results in hh:mm format if that is required, because
    that ability is not builtin. Google should provide many examples of doing
    this. I would search for

    vbscript format time duration hh:mm

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Jan 31, 2005
    #2
    1. Advertising

  3. How would it know if you go from 13:50 to 14:50 that you mean 1 hour, 25
    hours, 49 hours, etc.? You have to include a date to avoid this ambiguity.

    Ray at work

    "Wer" <> wrote in message
    news:...
    > Hi,
    >
    > I'm trying to add hours together in the format HH:MM + HH:MM. There
    > doesn't seem to be a functional part of DateAdd that will accomplish
    > this though ?
    >
    > The calculation is to work out how many hours have been spent on a
    > website so exceeding the 24:00 is fine.
    > Is there another function that would accomplish this ?
    >
    > Thanks
    >
    > W.
    >
    Ray Costanzo [MVP], Jan 31, 2005
    #3
  4. Wer

    Evertjan. Guest

    Wer wrote on 31 jan 2005 in microsoft.public.inetserver.asp.general:

    > I'm trying to add hours together in the format HH:MM + HH:MM. There
    > doesn't seem to be a functional part of DateAdd that will accomplish
    > this though ?


    Could be don but I prefer the hands on way below.

    > The calculation is to work out how many hours have been spent on a
    > website so exceeding the 24:00 is fine.
    > Is there another function that would accomplish this ?


    Using vbscript:

    time1 = "13:17"
    time2 = "12:51"

    time1a = split(time1,":")
    time2a = split(time2,":")

    mi = 1*time1a(1) + 1*time2a(1)
    hr = 1*time1a(0) + 1*time2a(0)

    if mi>59 then mi = mi-60 : hr = hr+1

    response.write hr & ":" & two(mi) ' writes 26:08

    function two(x)
    if x<10 then x = "0" & x
    two = x
    end function



    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Jan 31, 2005
    #4
  5. Wer

    Evertjan. Guest

    Ray Costanzo [MVP] wrote on 31 jan 2005 in
    microsoft.public.inetserver.asp.general:
    > "Wer" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> I'm trying to add hours together in the format HH:MM + HH:MM. There
    >> doesn't seem to be a functional part of DateAdd that will accomplish
    >> this though ?

    > How would it know if you go from 13:50 to 14:50 that you mean 1 hour,
    > 25 hours, 49 hours, etc.? You have to include a date to avoid this
    > ambiguity.


    Not the difference, Ray, but the sum was asked for.

    They are just amounts of time to be added.


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Jan 31, 2005
    #5
  6. My bad. :]

    Ray at work

    "Evertjan." <> wrote in message
    news:Xns95EFA4A798E3Deejj99@194.109.133.29...

    > Not the difference, Ray, but the sum was asked for.
    >
    > They are just amounts of time to be added.
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
    >
    Ray Costanzo [MVP], Jan 31, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Tapia

    DateAdd Function and error BC30451

    Matt Tapia, Aug 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,176
    Chris R. Timmons
    Aug 13, 2003
  2. Mel

    DateAdd Function

    Mel, Nov 4, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    6,018
  3. lofty

    DateAdd does not work

    lofty, Jul 20, 2003, in forum: ASP General
    Replies:
    5
    Views:
    172
    Chris Barber
    Jul 20, 2003
  4. Tipple
    Replies:
    2
    Views:
    124
    Tipple
    Oct 16, 2003
  5. Øyvind Isaksen

    dateadd()

    Øyvind Isaksen, Oct 17, 2003, in forum: ASP General
    Replies:
    4
    Views:
    135
    Ken Schaefer
    Oct 18, 2003
Loading...

Share This Page