tags:

views:

196

answers:

2

hi,

In my asp page, i write code like this for checking date validation

<%
'Session 1
session.lcid=2057
Session("CheckIn")= "26/12/2009"
d=0
response.write session("CheckIn")&"----"&DateAdd("d",d,Session("CheckIn")) &"<br/>"

if session("CheckIn")= DateAdd("d",d,Session("CheckIn")) then
response.write "Session 1 is workings"
end if

'Session 2
a ="26/12/2009"
b ="26/12/2009"
if a=b then
response.write "Session 2 is workings"
end if
%>

In the session 1 "if" condition is not working. But if i write date in string format in session 2, "IF" condition is working.

How i check "IF" condition in Session 1 in my classic asp page

hoping your response,

A: 

In your first case, DateAdd("d", d, Session("CheckIn")), the session value is implicitly converted to a DateTime data type, and so the DateAdd succeeds. However, to then compare to the session variable, I suspect it is being converted implicitly to a string using whatever the default format is (unlikely to be dd/mm/yyyy).

You need to make sure that the two values you are comparing are of the same type. I'd suggest:

if CDate(session("CheckIn")) = DateAdd("d",d,Session("CheckIn")) then

for your first check

David M
thanks a loooooooooooooot
Alex
+2  A: 

Hai Alex,

Use CDate function,

if CDate(a) > Cdate(b) then

 '.........

end if
Pandiya Chendur