SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Hinckley, England
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date Value Problem

    I've been coding ASP for a number of years but I'm really stumped by this one. Basically we are testing date values to see if a voucher is within date range and therefore valid.

    The start and end dates are pulled out of a database but I have hardcoded them in here to make things more simple.

    So the date today is February 7 2007, this means that the date is within our range and is valid. However the code is telling me it is not!

    The code runs as follows:

    Code:
    <%
    dateToday = Now()
    voucherStartDate = "14/01/2007"
    voucherEndDate = "28/02/2007"
    
    ' TEST THAT THE DATE RANGES ARE VALID
    If FormatDateTime(dateToday,1) < FormatDateTime(voucherStartDate,1) Then
    	Response.Write("<p>VOUCHER NOT STARTED")
    	Response.Write("<br />Date Today: " & FormatDateTime(dateToday,1))
    	Response.Write("<br />Voucher Start Date: " & FormatDateTime(voucherStartDate,1))
    	Response.Write("</p>")
    Else
    	If FormatDateTime(dateToday,1) > FormatDateTime(voucherEndDate,1) Then
    		Response.Write("<p>VOUCHER EXPIRED")
    		Response.Write("<br />Date Today: " & FormatDateTime(dateToday,1))
    		Response.Write("<br />Voucher End Date: " & FormatDateTime(voucherEndDate,1))
    		Response.Write("</p>")
    	Else
    		Response.Write("<p>Voucher Valid</p>")
    	End If		
    End If
    %>
    You can see an exact replica of this code working here where it isn't working correctly:
    http://www.jacksonscamping.com/voucherDateProblem.asp

    Apologies if it this is a really simple mistake, I have been looking at it for ages without solving it.

    An added complication is that I'm in the UK and we format dates differently to the US (I suspect this may be not helping my problem).

    Thanks in advance.

    David

  2. #2
    SitePoint Guru SSJ's Avatar
    Join Date
    Jan 2007
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have just copy-paste the code on my test page and run on the server.

    I got it working.
    I think there is a problem with date Formatting.

    -SSJ

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Hinckley, England
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the problem my lie with the Global.asa file which I have modified. Because we are in the UK I had to add the following lines so that curency is displayed in pounds and not dollars:

    Code:
    Sub Session_OnStart
    
         Session.LCID = 2057
         
    End Sub
    If I run the code on other servers without this modified Global.asa there is no problem.

    David

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you should convert all your variables and it should work like this:
    Code:
    <%
    dateToday = Now()
    voucherStartDate = "14/01/2007"
    voucherEndDate = "28/02/2007"
    
    ' TEST THAT THE DATE RANGES ARE VALID
    If FormatDateTime(cdate(dateToday),1) < FormatDateTime(cdate(voucherStartDate),1) Then
    	Response.Write("<p>VOUCHER NOT STARTED")
    	Response.Write("<br />Date Today: " & FormatDateTime(cdate(dateToday),1))
    	Response.Write("<br />Voucher Start Date: " & FormatDateTime(cdate(voucherStartDate),1))
    	Response.Write("</p>")
    Else
    	If FormatDateTime(dateToday,1) > FormatDateTime(voucherEndDate,1) Then
    		Response.Write("<p>VOUCHER EXPIRED")
    		Response.Write("<br />Date Today: " & FormatDateTime(cdate(dateToday),1))
    		Response.Write("<br />Voucher End Date: " & FormatDateTime(cdate(voucherEndDate),1))
    		Response.Write("</p>")
    	Else
    		Response.Write("<p>Voucher Valid</p>")
    	End If		
    End If
    %>
    I tried this on my server and it works.
    Hope this helps

  5. #5
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Hinckley, England
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nroussi View Post
    I tried this on my server and it works.
    Hope this helps
    Thank you for the suggestion however it's still throwing it out:
    http://www.jacksonscamping.com/voucherDateProblem.asp

    I'm now 100% sure that the Global.asa is causing the problem, I've uploaded your code to a different sub-domain that has an unmodified Global.asa and it works fine:
    http://www.jacksonscamping.com/voucherDateProblem.asp

    The joys of being a Brit.

    David


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •