473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Processing Date Input

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
Aug 1 '06 #1
5 1541
"Saitir" <Sa****@discussions.microsoft.comwrote in message
news:39**********************************@microsof t.com...
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.
Aug 1 '06 #2
For example
http://www.thecodeproject.com/vb/net...kerArticle.asp
PAtrick
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:O8**************@TK2MSFTNGP03.phx.gbl...
"Saitir" <Sa****@discussions.microsoft.comwrote in message
news:39**********************************@microsof t.com...
>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.

Aug 1 '06 #3
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" <ma**@markNOSPAMrae.comwrote in message
news:O8**************@TK2MSFTNGP03.phx.gbl...
"Saitir" <Sa****@discussions.microsoft.comwrote in message
news:39**********************************@microsof t.com...
>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.

Aug 1 '06 #4
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" <Sa****@discussions.microsoft.comwrote in message
news:39**********************************@microsof t.com...
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


Aug 1 '06 #5
"Patrick.O.Ige" <na********@hotmail.comwrote in message
news:ef**************@TK2MSFTNGP03.phx.gbl...
For example
http://www.thecodeproject.com/vb/net...kerArticle.asp
Or
https://secure.codeproject.com/aspne...teSelector.asp

Spot the difference :-)
Aug 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Danny Anderson | last post by:
Hola, PHP folk! I have a php page that contains a self-processing form. The form holds search results. The search terms originally came from the previous page, but the user can repeatedly...
8
by: dmcconkey | last post by:
Hi folks, I have a client with four websites. Each site has a contact form that is identical. They all have "required" fields validated through a JavaScript onSubmit() function. Upon validation,...
5
by: billa | last post by:
I wish to carry out standard form validation (i.e. is it a date?, is there a value in the field, is it a number) using the onBlur event rather than the onSubmit event. This (of course) leads to...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
9
by: Andrew Gwozdziewycz | last post by:
I've been looking recently for date processing modules that can parse dates in forms such as "next week" or "6 days from next sunday". PHP has a function that will do this called 'strtotime',...
3
by: raj chahal | last post by:
Hi there i have created a registration page containing a form than sends username password to an asp processing page. If the user exists it sends the user back to the registration page with...
0
by: oneplace | last post by:
I have the following script that use for the following after i have made my search for a name in my database. I select the name and it bring up this from with all the information of the person. It...
8
numberwhun
by: numberwhun | last post by:
Hello everyone! I am dabbling in processing forms using Perl and having only just begun, I am already having problems. Go figure. :-) Top begin with, here it the form's html, its nothing at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.