Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Time diff

Reply
Thread Tools

Time diff

 
 
magix
Guest
Posts: n/a
 
      08-20-2007
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


 
Reply With Quote
 
 
 
 
David Morgan
Guest
Posts: n/a
 
      08-21-2007

"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


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      08-21-2007
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)
 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      08-21-2007
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.


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-21-2007
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)
 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      08-21-2007
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.


 
Reply With Quote
 
Bookham Measures
Guest
Posts: n/a
 
      08-23-2007

"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.


 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      08-23-2007
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
Diff CSS styles for diff INPUT TYPE='s? A Traveler ASP .Net 6 08-31-2004 09:17 PM
[ANN] Diff::LCS 1.1.0, Diff::LCS 1.0.4 Austin Ziegler Ruby 3 08-09-2004 06:34 AM
diff Process under diff users Cyril Vi?ville Perl 1 06-29-2004 06:22 PM
Same sessionID retuned to diff browsers in diff machines Berrucho ASP .Net 2 12-05-2003 02:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57