(Date + 10 * 1 / 24) = ((Date + 8 * 1 / 24) + 2 * 1 / 24 ) return false

P

Pan Yang Bin

Hi,
I using the following script to output 10 o'clock, the first two
return corrent result, and i also check the year, month, day, hour,
minute, second function they all return same result. but the third one
output false, can anyone tell me why this happen? thanx.

<%
response.write Date + 10 * 1 / 24
response.write ((Date + 8 * 1 / 24) + 2 * 1 / 24 )
response.write Date + 10 * 1 / 24 = ((Date + 8 * 1 / 24) + 2 * 1 /
24 )

%>
(i test it in both IIS6 and IIS5)
 
E

Evertjan.

Pan Yang Bin wrote on 23 sep 2004 in
I using the following script to output 10 o'clock, the first two
return corrent result, and i also check the year, month, day, hour,
minute, second function they all return same result. but the third one
output false, can anyone tell me why this happen? thanx.

<%
response.write Date + 10 * 1 / 24
response.write ((Date + 8 * 1 / 24) + 2 * 1 / 24 )
response.write Date + 10 * 1 / 24 = ((Date + 8 * 1 / 24) + 2 * 1 / 24 )

%>
(i test it in both IIS6 and IIS5)

It is always a bad idea to test for equal floating points.

vbs is right, they are not exact equivalents:

a= Date() + 10 * 1 / 24
b= (Date() + 8 * 1 / 24) + 2 * 1 / 24
c = a - b
response.write c

' returns -7,27595761418343E-12 [in IE-vbs]

' so try this:

response.write c < 1e-9

' returns true
 
P

Phill. W

Pan Yang Bin said:
I using the following script to output 10 o'clock

Forgive me, but surely this is clearer ...

Response.Write DateAdd( "h", 10, Date() )

HTH,
Phill W.
 
P

Pan Yang Bin

The actual case is to get the data from oracle database, and to get
the result like (Date + 10 * 1 / 24) = ((Date + 8 * 1 / 24) + 2 * 1 /
24 )

date1
set rs = conn.execute("SELECT TRUNC(SYSDATE) + 8/24 FROM DUAL")
date1 = rs(0).value
rs.close

set rs = conn.execute("SELECT TRUNC(reltime, 'hh24') FROM tablea")
date2 = rs(0).value 'the actual SQL
rs.close

for i = 0 to 23
if date1 + i * 1/24 = date2 then
response.write "True"
end if
next

so even when i use DateAdd( "h", 10, Date() ) function, the result is
still same -- false.

I think what Evertjan said is the root cause, but everytime to check
in this way is very painful.

i also check "= (today() + 10 * 1 / 24) = ((today() + 8 * 1 / 24) + 2
* 1 / 24 )"
in excel cell with above formula it return true.

and using "SELECT 1 FROM (TRUNC(SYSDATE) + 10 * 1 / 24) =
((TRUNC(SYSDATE) + 8 * 1 / 24) + 2 * 1 / 24 )" it return 1

unfortunately, when i test it in VB/VBA/VBScript, it fails.
 
P

Pan Yang Bin

and using "SELECT 1 FROM DUAL WHERE (TRUNC(SYSDATE) + 10 * 1 / 24) =
((TRUNC(SYSDATE) + 8 * 1 / 24) + 2 * 1 / 24 )" it return 1 IN ORACLE
 
E

Evertjan.

Pan Yang Bin wrote on 24 sep 2004 in
microsoft.public.inetserver.asp.general:
date1
set rs = conn.execute("SELECT TRUNC(SYSDATE) + 8/24 FROM DUAL")
date1 = rs(0).value
rs.close

1/24 is NOT an hour converted to in binary but an approximation
testing to the nearest second.
Would this be correct in ASP vbs?

if rs(date1)+8/24-rs(date2) < 1/24/60/60 then ...
so even when i use DateAdd( "h", 10, Date() ) function, the result is
still same -- false.

1
Could you try:
Datediff("s", timedate2, DateAdd("h",10,timedate1) )=0

2
Perhaps in your type of SQL date() will give you date/time,
while in vbscript date() gives only the date ?

3
Try setting "breakpoints" showing the exact times, for debugging,
like:

response.write timedate1 & "<br>"
.....
response.write timedate2 & "<br>"
 

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
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top