Time diff

Discussion in 'ASP General' started by magix, Aug 20, 2007.

  1. magix

    magix Guest

    Dear Guru,

    If I want to compare time, what is the best approach to go ? Any good
    example ? DateDiff ( ) ?

    Pseudocode
    ========

    submitdate = rs.fields("submissiondate") -> submissiondate is a date field
    in a table.

    if time for submitdate < = 8:15am then
    do something A
    elseif time for submitdate <= 10:15am then
    do something B
    elseif time for submitdate <= 12:15pm then
    do something C
    else
    do something D


    thank you very much !

    Magix
     
    magix, Aug 20, 2007
    #1
    1. Advertising

  2. magix

    David Morgan Guest

    "magix" <> wrote in message
    news:46c9be3e$...
    > Dear Guru,
    >
    > If I want to compare time, what is the best approach to go ? Any good
    > example ? DateDiff ( ) ?
    >
    > Pseudocode
    > ========
    >
    > submitdate = rs.fields("submissiondate") -> submissiondate is a date
    > field in a table.
    >
    > if time for submitdate < = 8:15am then
    > do something A
    > elseif time for submitdate <= 10:15am then
    > do something B
    > elseif time for submitdate <= 12:15pm then
    > do something C
    > else
    > do something D
    >
    >
    > thank you very much !
    >
    > Magix
    >


    If submitdate < #08:16:00# Then
    DoA
    ElseIf submitdate < #10:16:00# Then
    DoB
    Else
    DoD
    End If
     
    David Morgan, Aug 21, 2007
    #2
    1. Advertising

  3. magix

    Evertjan. Guest

    David Morgan wrote on 21 aug 2007 in
    microsoft.public.inetserver.asp.general:

    >
    > "magix" <> wrote in message
    > news:46c9be3e$...
    >> Dear Guru,
    >>
    >> If I want to compare time, what is the best approach to go ? Any good
    >> example ? DateDiff ( ) ?
    >>
    >> Pseudocode
    >> ========
    >>
    >> submitdate = rs.fields("submissiondate") -> submissiondate is a date
    >> field in a table.
    >>
    >> if time for submitdate < = 8:15am then
    >> do something A
    >> elseif time for submitdate <= 10:15am then
    >> do something B
    >> elseif time for submitdate <= 12:15pm then
    >> do something C
    >> else
    >> do something D
    >>
    >>
    >> thank you very much !
    >>
    >> Magix
    >>

    >
    > If submitdate < #08:16:00# Then
    > DoA
    > ElseIf submitdate < #10:16:00# Then
    > DoB
    > Else
    > DoD
    > End If


    This will only work if submitdate is also a time and not a date-time.

    Try this to see what I mean:

    <% = year(#08:16:00#) %>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 21, 2007
    #3
  4. magix wrote:
    > Dear Guru,
    >
    > If I want to compare time, what is the best approach to go ? Any good
    > example ? DateDiff ( ) ?
    >
    > Pseudocode
    > ========
    >
    > submitdate = rs.fields("submissiondate") -> submissiondate is a date
    > field in a table.
    >
    > if time for submitdate < = 8:15am then
    > do something A
    > elseif time for submitdate <= 10:15am then
    > do something B
    > elseif time for submitdate <= 12:15pm then
    > do something C
    > else
    > do something D
    >
    >

    You need to extract the time component from the datetime value being
    retrieved from the database. One way to do that is to realize that
    vbscript uses a Double to store the datetime, with the time of day
    stored in the decimal portion. So, you would do this:

    dim decimaldatetime
    decimaldatetime = cdbl(submitdate)
    dim submittime
    submittime = cdate(decimaldatetime - int(decimaldatetime))

    if submittime <= #08:15# then
    elseif submittime <= #10:15# then
    elseif submittime <= #12:15# then
    else
    end if

    --
    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], Aug 21, 2007
    #4
  5. magix

    Evertjan. Guest

    Bob Barrows [MVP] wrote on 21 aug 2007 in
    microsoft.public.inetserver.asp.general:

    > ou need to extract the time component from the datetime value being
    > retrieved from the database. One way to do that is to realize that
    > vbscript uses a Double to store the datetime, with the time of day
    > stored in the decimal portion. So, you would do this:
    >
    > dim decimaldatetime
    > decimaldatetime = cdbl(submitdate)
    > dim submittime
    > submittime = cdate(decimaldatetime - int(decimaldatetime))


    submittime = timevalue(submitdate)

    > if submittime <= #08:15# then
    > elseif submittime <= #10:15# then
    > elseif submittime <= #12:15# then
    > else
    > end if


    ==========================

    In fact, all time only values are really dated on 1899/12/30.

    Try:

    <script type='text/vbscript'>
    d = now
    x = timevalue(d)
    alert(x)
    alert(year(x))
    alert(month(x))
    alert(day(x))
    </script>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 21, 2007
    #5
  6. Evertjan. wrote:
    > submittime = timevalue(submitdate)
    >

    !
    Never saw that one!
    And of course, there's a DateValue function I've never used!

    --
    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], Aug 21, 2007
    #6
  7. "Bob Barrows [MVP]" <> wrote in message
    news:u%...
    > Evertjan. wrote:
    >> submittime = timevalue(submitdate)
    >>

    > !
    > Never saw that one!
    > And of course, there's a DateValue function I've never used!
    >
    > --
    > 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.
    >
    >


    Although you'd want TimeValue.

    The 1899 date is always how SQL stores time only values. Presume it is
    significant from an integer point of view.
     
    Bookham Measures, Aug 23, 2007
    #7
  8. Bookham Measures wrote:
    > "Bob Barrows [MVP]" <> wrote in message
    > news:u%...
    >> Evertjan. wrote:
    >>> submittime = timevalue(submitdate)
    >>>

    >> !
    >> Never saw that one!
    >> And of course, there's a DateValue function I've never used!

    >
    > Although you'd want TimeValue.

    Huh?
    Oh, I see. No, I was only pointing out the existance of DateVale, not
    suggesting its use in this situation.
    >
    > The 1899 date is always how SQL stores time only values.

    :)
    Why is what "SQL" does relevant? We are discussing only vbscript
    variables and functions here. How SQL stores datetimes is irrelevant.
    :)
    Also, the seed date used does vary depending on the database being used.
    For example, I believe Jet uses 1/1/1900 - I may be wrong, and I don't
    have time to go check it, but I do know it's a different seed date than
    what SQL Server uses.

    --
    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], Aug 23, 2007
    #8
    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. Cyril Vi?ville

    diff Process under diff users

    Cyril Vi?ville, Jun 29, 2004, in forum: Perl
    Replies:
    1
    Views:
    513
    Joe Smith
    Jun 29, 2004
  2. Berrucho
    Replies:
    2
    Views:
    642
    Infant Newbie
    Dec 5, 2003
  3. A Traveler

    Diff CSS styles for diff INPUT TYPE='s?

    A Traveler, Aug 31, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,930
    Steve Fulton
    Aug 31, 2004
  4. flamesrock
    Replies:
    8
    Views:
    477
    Hendrik van Rooyen
    Nov 24, 2006
  5. Austin Ziegler

    [ANN] Diff::LCS 1.1.0, Diff::LCS 1.0.4

    Austin Ziegler, Aug 8, 2004, in forum: Ruby
    Replies:
    3
    Views:
    196
    Austin Ziegler
    Aug 9, 2004
Loading...

Share This Page