Time diff

M

magix

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
 
D

David Morgan

magix said:
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
 
E

Evertjan.

David Morgan wrote on 21 aug 2007 in
microsoft.public.inetserver.asp.general:
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#) %>
 
B

Bob Barrows [MVP]

magix said:
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
 
E

Evertjan.

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>
 
B

Bookham Measures

Bob Barrows said:
!
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.
 
B

Bob Barrows [MVP]

Bookham said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top