473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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)
Jul 19 '05 #1
5 1565
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

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 19 '05 #2
"Pan Yang Bin" <pa***@hotmail.com> wrote in message
news:f2**************************@posting.google.c om...
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.
Jul 19 '05 #3
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.
Jul 19 '05 #4
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
Jul 19 '05 #5
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>"

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: w i l l | last post by:
Why does this work the way it does? If someone could explain return true, and return false to me I'd greatly appreciate it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ...
1
by: philjhanna | last post by:
Hi I'm having a problem applying return false to a div via addEventListener. I'm adding this so that I can drag (click-hold-move) over an image. (Its so that I can add zooming to the image)...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
13
by: alvin.yk | last post by:
Hi, Normally, a piece of code such as <a href="http://www.yahoo.com" onclick="alert('hello');return false;">link</a> will stop the browser from actually going to href's destination....
4
by: ameyas | last post by:
hi all, i am using an image which has image map and i provide the href action url. i have provided the url to open a pop up window like "javascript:window.open('www.google.com');" but on...
8
by: Peter Afonin | last post by:
Hello, I'm using Javascript in ASP.NET application to check whether at least one checkbox in datagrid has been checked. If validation fails, the user gets a warning. If he clicks OK, the form is...
1
by: prashanth023 | last post by:
Hi, This is prashanth kumar. I am getting error , i am gettign number of records using ajax. Please solve this if n >0 i am putting return false in response function. but form is going to...
5
by: GiJeet | last post by:
Hello, I'm trying to figure this code out. <input type="submit" onclick="if(!confirm('Are you sure?') return false; "... /> I know that if you return false in an event like this onclick it...
5
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
2
Soniad
by: Soniad | last post by:
Hi, I have ASP page where there are three tabs,each showing different content. Each tab have cancel button and save button. If validation is proper; then, Save button submits the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.