Forum Moderators: open

Message Too Old, No Replies

ASP Dates from Request.Form

         

andrevr

3:51 pm on Jul 10, 2005 (gmt 0)

10+ Year Member



I have a problem when I retrieve a date into a var from a input box on ASP page, using Request.Form
Depending on the date, the returned value seems to be either dd/mm/yyyy or mm/dd/yyyy. Of course, this wreaks havoc when I post the date into a SQL database.

I'm using the POST method on the first page.
Say the input is named "edtDate". (The test is run on the IIS server PC, regional settings are dd/mm/yyyy).

On the second page I use:

OrdDate = Request.Form("edtDate")
Response.Write("The date = " & OrdDate & "; The Day part is = " & Day(OrdDate))

If I enter "23/07/2005" on the first page, the output is:
The date = 23/07/2005; The Day part is = 23
OK, all's well...

If I enter "01/07/2005" on the first page, the output is:
The date = 01/07/2005; The Day part is = 7
Huh? Wassssup?

Anyone have a idea? Please....

mattglet

4:53 pm on Jul 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should build a date picker using dropdown menu choices. Don't let the user enter in free flowing text, make them choose the numbers from the menu:

<select name = "month">
<option value = "1">January</option>
<option value = "2">February</option>
...
</select>

<select name = "day">
<option value = "1">1</option>
<option value = "2">2</option>
...
</select>

<select name = "year">
<option value = "2005">2005</option>
<option value = "2006">2006</option>
...
</select>

aspdaddy

5:02 pm on Jul 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or use a format that cannot be mis-interpreted, like dd-mon-yyyy

andrevr

11:03 pm on Jul 10, 2005 (gmt 0)

10+ Year Member



Thanks for your ideas guys... but the effort of getting the individual combo's right with 31 days for Jan, March,... and 30 days for April, June,.... and 28 days for Feb except on leap years...etc just seemed like too much code, and the date formats that are more stable too uncomfortable for the (inflexible) grannies that use the app...so...

After a bit of thinking round the issue.. I did this:

OrdDate = Request.Form("datOrd")
dtOrdDate = FixDate(OrdDate)

Function FixDate(TargetDate)
if Day(TargetDate) < 13 then
dtDate = Month(TargetDate)
dtMonth = Day(TargetDate)
else
dtDate = Day(TargetDate)
dtMonth = Month(TargetDate)
end if
FixDate = dtDate & "/" & dtMonth & "/" & Year(TargetDate)
End Function

Yup, I know it's about as elegant as a swift kick in the @#$'s, but it works...

What interests me, is how I can find no real, clean, proper fix for something which is obviously a bug in the ASP.dll? Thanks again, Bill :))

mattglet

1:58 am on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's definitely not a lot of code to write for the proper day checking. It's just some javascript that needs to be implemented.

Woz

2:19 am on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first thing I would be doing would be to set the LocaleID for the page to force the Date Format. Would you believe the best list of them I coudl find is on a non-microsoft site? Over here [tdsf.co.uk].

That way you will know that the second figure will always be the Day, or the Month, depending on the locale you set. I learned this the hard way when a host apparently changed the localeID of the server, despite insisting they didn't, and all my dates appeared as if from Klingon.

Once you have set the LocalID, then construct your form with three different fields [eg, day/month/year] and plaster the format on the form in BIG LETTERS to make sure your users input correctly - well, most of them anyway.

Onya
Woz

mrMister

3:22 am on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



something which is obviously a bug in the ASP.dll

Erm, yeah.... obviously! 8-)

It sounds to me like your server's regional settings are set to US. Have a look, and change them to GB/UK.

I wouldn't use your fudge code unless you can absolutely help it. When you change servers, it will more than likely mess up again.

Woz

3:28 am on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you change servers, it will more than likely mess up again.

By setting the LocaleID on all pages, you are independant of the Server Locale setting and so avoids these sorts of problems when moving servers.

Onya
Woz

andrevr

7:39 am on Jul 11, 2005 (gmt 0)

10+ Year Member



Morning guys :)

Firstly, may I just say thank you. This has to be the most responsive forum I have ever used to get help.

Background. I'm primarily a Delphi developer. I work alone, no one to lean over to and ask, no mentor. I got into ASP after my ASP sub-contractor let me down by 3 weeks and almost torpedo'd my relationship with an excellent customer..so I hit the books and the web, and here I am. So what a pleasure to find a forum where everyone is up to help, esp the senior guys. Thanks.

Mattglet: I have Delphi, ASP, ISAPI in my box. I use Java sparingly, cos I can't write or debug it. I wish I could, but...

Woz: I did the web search thing, found the article on MSDN, and tried setting both Session and Response LCID. No change. Remember the results are not consistently mm/dd/yyyy or dd/mm/yyyy, but change as the day reaches 13. So 01/07/2005 returns day = 7 month = 1, and 14/07/2005 returns day = 14 month = 7.

MrMister: First place I looked. Interestingly the server was set to yyyy/mm/dd. Tried setting it to dd/mm/yyyy and mm/dd/yyyy. No difference. Seems to be ignoring that setting completely. That's when I went looking for a way to force the issue and found the LCID settings, which also made no difference. I agree wholeheartedly about using fudge code, I do, really :) But I have a customer posting accounting system entries using the ASP right now, so my time to research is under pressure. I promise not to let it lie there tho'

I'll probably do the three fields thing in ASP or a Delphi ASP component to fix it properly and permanently as soon as I can.

Thanks again, and I hope I'll be able to help someone else like you guys have helped me. I'll be baaak :)