468,550 Members | 2,435 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,550 developers. It's quick & easy.

asp if date&time based if statement

120 100+
I can display server date, time using the asp now() function but im having trouble writing an asp if statement based on a date & time condition - so if date,time = something do something otherwise do something else.

this is my attempt
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim varNow, expTime 'create variable that will store date and time
  3. varNow=Now 'the Now function returns the date & time - assign it to the variable
  4. expTime="10/05/2010 13:00:00"
  6. IF varNow => expTime THEN
  7.     Response.write "<a class=""button"" href=""javascript:popWin('place-bid.asp','250','320')"">Place Bid</a>"
  8. Else
  9.     Response.write "<span style=""color:#cc0000; font-weight:bold; font-style:italic"">Auction has ended.</span>"
  10. END IF
  11. %> 
however regardless of what I set within 'expTime' the page always returns Auction has ended which doesnt make sense.

Please advise.
May 10 '10 #1
2 3722
Hey there is a problem in the date format . . Try the below code . .

Dim varNow, expTime 'create variable that will store date and time
varNow=Now 'the Now function returns the date & time - assign it to the variable
expTime="05/11/2010 13:00:00"

Response.Write(CDate(expTime)) & "<br>"
Response.Write(CDate(varNow)) & "<br>"
'IF Cdate(varNow) > cdate(expTime) THEN
Response.Write DateDiff("d",CDate(expTime),CDate(varNow)) & "<br>"

if DateDiff("d",CDate(expTime),CDate(varNow))< 0 then
Response.write "<a class=""button"" href=""javascript:popWin('place-bid.asp','250','320')"">Place Bid</a>"
Response.write "<span style=""color:#cc0000; font-weight:bold; font-style:italic"">Auction has ended.</span>"

Reply the post if still you have problem . . .

May 12 '10 #2
3,405 Expert 2GB
nedu is right. varnow is a date type variable, but expDate is a string, they will never compare correctly. I was going to suggest using
Expand|Select|Wrap|Line Numbers
  1. expTime= cdate("05/11/2010 13:00:00")
May 18 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Tim Williams (gmail) | last post: by
2 posts views Thread by msnews.microsoft.com | last post: by
3 posts views Thread by Atreju | last post: by
4 posts views Thread by David | last post: by
6 posts views Thread by Mike Charney | last post: by
2 posts views Thread by psycho | last post: by
1 post views Thread by jestin | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.