Time Comparison - why is this not working?
am 18.01.2007 14:56:21 von Joey Martin
Please look at code below. I am trying to compare the NOW time with a
"deadline" time. Please help. Just not sure why this is not working. I
need to be able to say IF IT'S BEFORE 9:30 TODAY, IT'S OKAY TO ADD
SOMETHING. IF IT'S AFTER 9:30 TODAY, YOU MUST ADD IT TOMORROW.
CODE:
nowtime=now()
deadlinetime=formatdatetime(now(),2) + " 8:30:00 AM"
response.write "NOW: " & nowtime & "
"
response.write "Deadline: " & deadlinetime & "
"
if nowtime
if nowtime>deadlinetime then response.write "must send out tomorrow" end
if
RESULTS:
NOW: 1/18/2007 8:51:43 AM
Deadline: 1/18/2007 8:30:00 AM
can send out today
As you can see, NOW is GREATER THAN Deadline, so it should must send out
tomorrow.
*** Sent via Developersdex http://www.developersdex.com ***
Re: Time Comparison - why is this not working?
am 18.01.2007 15:31:59 von exjxw.hannivoort
Joey Martin wrote on 18 jan 2007 in
microsoft.public.inetserver.asp.general:
>
> Please look at code below. I am trying to compare the NOW time with a
> "deadline" time. Please help. Just not sure why this is not working. I
> need to be able to say IF IT'S BEFORE 9:30 TODAY, IT'S OKAY TO ADD
> SOMETHING. IF IT'S AFTER 9:30 TODAY, YOU MUST ADD IT TOMORROW.
>
> CODE:
> nowtime=now()
> deadlinetime=formatdatetime(now(),2) + " 8:30:00 AM"
> response.write "NOW: " & nowtime & "
"
> response.write "Deadline: " & deadlinetime & "
"
> if nowtime
> if nowtime>deadlinetime then response.write "must send out tomorrow" end
Those variables will be compared as strings, letter by letter!
Make datevalues!
Try:
nowtime = time()
deadlinetime = #08:30:00#
response.write "Now: " & nowtime & "
"
response.write "Deadline: " & deadlinetime & "
"
if nowtime < deadlinetime then
response.write "can send out today"
else
response.write "must send out tomorrow"
end if
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Re: Time Comparison - why is this not working?
am 18.01.2007 15:34:10 von reb01501
Joey Martin wrote:
> Please look at code below. I am trying to compare the NOW time with a
> "deadline" time. Please help. Just not sure why this is not working. I
> need to be able to say IF IT'S BEFORE 9:30 TODAY, IT'S OKAY TO ADD
> SOMETHING. IF IT'S AFTER 9:30 TODAY, YOU MUST ADD IT TOMORROW.
>
> CODE:
> nowtime=now()
> deadlinetime=formatdatetime(now(),2) + " 8:30:00 AM"
formatdatetime returns a string. You are doing a string comparison
instead of a datetime comparison. Change this to:
deadlinetime = dateadd("n",30,dateadd("h",8,date()))
or, if you are committed to using formatdatetime, do this:
deadlinetime=formatdatetime(now(),2) + " 8:30:00 AM"
deadlinetime=CDate(deadlinetime)
Personally, I prefer the former
--
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.