Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Processing Date Input

Reply
Thread Tools

Processing Date Input

 
 
=?Utf-8?B?U2FpdGly?=
Guest
Posts: n/a
 
      08-01-2006
Example:

On a web page the user enters for a date: 12/05/2006
They're in the UK, so this is 12th May 2006
Once this value arrives in a datetime variable in VB, date.month = 12 and
not 5 as should be expected, ie, it has assumed a US date formatting.

We have tried the following:

Setting both
System.Threading.Thread.CurrentThread.CurrentCultu re
System.Threading.Thread.CurrentThread.CurrentUICul ture

to "EN-GB"

And

Dim ukCulture As CultureInfo = New CultureInfo("en-GB")
Dim myDateTime As DateTime = DateTime.Parse(myDate, ukCulture.DateTimeFormat)

Neither of these approaches have resolved the fundamental issue (US format
in the resulting variable rather than a UK date (month - day swapped).

Also, .ToString versions of the variables have been passed around, using a
string to capture the variable before processing and so on.

Also, once you change the input date to something like 28/1/2006, the
processes fail to even accept it as a valid date format (obviously because 28
is greater than the maximum month of 12)

Control Panel on the development machine shows Uk/British settings in all
appropriate places.

Is there a way (and there surely must be?) to set ASP/VB.Net to use local
settings by default when processing this data? Or a genuine way of
converting between types that is actually reliable and doesn't require us to
make an assumption that the date is in x format so we can string strip and
rearrange.

Using Visual Studio 2005 Professional on XP Pro SP2, all known updates and
patches installed, with the environment being on this single machine.

Thanks


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      08-01-2006
"Saitir" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> On a web page the user enters for a date: 12/05/2006
> They're in the UK, so this is 12th May 2006
> Once this value arrives in a datetime variable in VB, date.month = 12 and
> not 5 as should be expected, ie, it has assumed a US date formatting.


> Is there a way (and there surely must be?) to set ASP/VB.Net to use local
> settings by default when processing this data? Or a genuine way of
> converting between types that is actually reliable and doesn't require us
> to
> make an assumption that the date is in x format so we can string strip and
> rearrange.


There is only one 100% guaranteed way for dates to be completely unambiguous
across all cultures:

FORMAT THEM PROPERLY!!!

If you absolutely *MUST* allow users to enter dates manually (i.e. not
through some sort of date picker control or whatever), then you must
reformat the date as soon as it has been entered in the following format:

dd MMM yyyy

No matter where you are in the world 12 May 2006 cannot be misinterpreted as
anything else.

However, I strongly urge you to use a date picker - there are loads of them
on the web.


 
Reply With Quote
 
 
 
 
Patrick.O.Ige
Guest
Posts: n/a
 
      08-01-2006
For example
http://www.thecodeproject.com/vb/net...kerArticle.asp
PAtrick
"Mark Rae" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Saitir" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> On a web page the user enters for a date: 12/05/2006
>> They're in the UK, so this is 12th May 2006
>> Once this value arrives in a datetime variable in VB, date.month = 12 and
>> not 5 as should be expected, ie, it has assumed a US date formatting.

>
>> Is there a way (and there surely must be?) to set ASP/VB.Net to use local
>> settings by default when processing this data? Or a genuine way of
>> converting between types that is actually reliable and doesn't require us
>> to
>> make an assumption that the date is in x format so we can string strip
>> and
>> rearrange.

>
> There is only one 100% guaranteed way for dates to be completely
> unambiguous across all cultures:
>
> FORMAT THEM PROPERLY!!!
>
> If you absolutely *MUST* allow users to enter dates manually (i.e. not
> through some sort of date picker control or whatever), then you must
> reformat the date as soon as it has been entered in the following format:
>
> dd MMM yyyy
>
> No matter where you are in the world 12 May 2006 cannot be misinterpreted
> as anything else.
>
> However, I strongly urge you to use a date picker - there are loads of
> them on the web.
>



 
Reply With Quote
 
Saitir
Guest
Posts: n/a
 
      08-01-2006
That's great, and true.

However, it doesn't alter the basic point that the date conversion tools
don't convert between two well formatted date types as they're supposed to.

I'm all for work arounds and so on, but when the tools are supposed to do
something, I'd prefer them to.

"Mark Rae" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Saitir" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> On a web page the user enters for a date: 12/05/2006
>> They're in the UK, so this is 12th May 2006
>> Once this value arrives in a datetime variable in VB, date.month = 12 and
>> not 5 as should be expected, ie, it has assumed a US date formatting.

>
>> Is there a way (and there surely must be?) to set ASP/VB.Net to use local
>> settings by default when processing this data? Or a genuine way of
>> converting between types that is actually reliable and doesn't require us
>> to
>> make an assumption that the date is in x format so we can string strip
>> and
>> rearrange.

>
> There is only one 100% guaranteed way for dates to be completely
> unambiguous across all cultures:
>
> FORMAT THEM PROPERLY!!!
>
> If you absolutely *MUST* allow users to enter dates manually (i.e. not
> through some sort of date picker control or whatever), then you must
> reformat the date as soon as it has been entered in the following format:
>
> dd MMM yyyy
>
> No matter where you are in the world 12 May 2006 cannot be misinterpreted
> as anything else.
>
> However, I strongly urge you to use a date picker - there are loads of
> them on the web.
>



 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      08-01-2006
Saitir,

I think that Mark has given you good advice. Using a date picker will make
the page work for anyone, anywhere, but if you want to you can localize it
for Great Brittain.

You are running into a conversion problem because by default the date is
coming into the system as a US date. You have to change what the page
considers to be the default format. This is done through localization.
Please see the following article Microsoft document, I think it will help:
http://msdn2.microsoft.com/en-us/library/fw69ke6f.aspx

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche


"Saitir" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Example:
>
> On a web page the user enters for a date: 12/05/2006
> They're in the UK, so this is 12th May 2006
> Once this value arrives in a datetime variable in VB, date.month = 12 and
> not 5 as should be expected, ie, it has assumed a US date formatting.
>
> We have tried the following:
>
> Setting both
> System.Threading.Thread.CurrentThread.CurrentCultu re
> System.Threading.Thread.CurrentThread.CurrentUICul ture
>
> to "EN-GB"
>
> And
>
> Dim ukCulture As CultureInfo = New CultureInfo("en-GB")
> Dim myDateTime As DateTime = DateTime.Parse(myDate,
> ukCulture.DateTimeFormat)
>
> Neither of these approaches have resolved the fundamental issue (US format
> in the resulting variable rather than a UK date (month - day swapped).
>
> Also, .ToString versions of the variables have been passed around, using a
> string to capture the variable before processing and so on.
>
> Also, once you change the input date to something like 28/1/2006, the
> processes fail to even accept it as a valid date format (obviously because
> 28
> is greater than the maximum month of 12)
>
> Control Panel on the development machine shows Uk/British settings in all
> appropriate places.
>
> Is there a way (and there surely must be?) to set ASP/VB.Net to use local
> settings by default when processing this data? Or a genuine way of
> converting between types that is actually reliable and doesn't require us
> to
> make an assumption that the date is in x format so we can string strip and
> rearrange.
>
> Using Visual Studio 2005 Professional on XP Pro SP2, all known updates and
> patches installed, with the environment being on this single machine.
>
> Thanks
>
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      08-01-2006
"Patrick.O.Ige" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> For example
> http://www.thecodeproject.com/vb/net...kerArticle.asp


Or
https://secure.codeproject.com/aspne...teSelector.asp

Spot the difference


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing input date and system date anagai Javascript 5 10-22-2007 01:05 AM
Input Date Is Between 2 DB Date Records rn5a@rediffmail.com ASP General 2 05-14-2007 01:57 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Compare Input Date to Server Date Scott Knapp Javascript 2 10-02-2003 07:20 PM



Advertisments