asp if date&time based if statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omar999
    New Member
    • Mar 2010
    • 120

    #1

    asp if date&time based if statement

    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
    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="10/05/2010 13:00:00"
    
    IF varNow => expTime THEN
    	Response.write "<a class=""button"" href=""javascript:popWin('place-bid.asp','250','320')"">Place Bid</a>"
    Else
    	Response.write "<span style=""color:#cc0000; font-weight:bold; font-style:italic"">Auction has ended.</span>"
    END IF
    %>
    however regardless of what I set within 'expTime' the page always returns Auction has ended which doesnt make sense.

    Please advise.
  • nedu
    New Member
    • Nov 2006
    • 65

    #2
    Originally posted by omar999
    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
    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="10/05/2010 13:00:00"
    
    IF varNow => expTime THEN
    	Response.write "<a class=""button"" href=""javascript:popWin('place-bid.asp','250','320')"">Place Bid</a>"
    Else
    	Response.write "<span style=""color:#cc0000; font-weight:bold; font-style:italic"">Auction has ended.</span>"
    END IF
    %>
    however regardless of what I set within 'expTime' the page always returns Auction has ended which doesnt make sense.

    Please advise.
    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",CD ate(expTime),CD ate(varNow)) & "<br>"

    if DateDiff("d",CD ate(expTime),CD ate(varNow))< 0 then
    Response.write "<a class=""button" " href=""javascri pt:popWin('plac e-bid.asp','250', '320')"">Place Bid</a>"
    Else
    Response.write "<span style=""color:# cc0000; font-weight:bold; font-style:italic""> Auction has ended.</span>"
    END IF
    %>

    Reply the post if still you have problem . . .

    Regards
    Nedu
    Last edited by nedu; May 12 '10, 02:24 PM. Reason: a

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      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
      Code:
      expTime= cdate("05/11/2010 13:00:00")

      Comment

      Working...