Processing Date Input

Discussion in 'ASP .Net' started by =?Utf-8?B?U2FpdGly?=, Aug 1, 2006.

  1. 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.CurrentCulture
    System.Threading.Thread.CurrentThread.CurrentUICulture

    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
     
    =?Utf-8?B?U2FpdGly?=, Aug 1, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?U2FpdGly?=

    Mark Rae Guest

    "Saitir" <> wrote in message
    news:...

    > 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.
     
    Mark Rae, Aug 1, 2006
    #2
    1. Advertising

  3. For example
    http://www.thecodeproject.com/vb/net/dwDatePickerArticle.asp
    PAtrick
    "Mark Rae" <> wrote in message
    news:...
    > "Saitir" <> wrote in message
    > news:...
    >
    >> 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.
    >
     
    Patrick.O.Ige, Aug 1, 2006
    #3
  4. =?Utf-8?B?U2FpdGly?=

    Saitir Guest

    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" <> wrote in message
    news:...
    > "Saitir" <> wrote in message
    > news:...
    >
    >> 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.
    >
     
    Saitir, Aug 1, 2006
    #4
  5. 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" <> wrote in message
    news:...
    > 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.CurrentCulture
    > System.Threading.Thread.CurrentThread.CurrentUICulture
    >
    > 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
    >
    >
     
    S. Justin Gengo, Aug 1, 2006
    #5
  6. =?Utf-8?B?U2FpdGly?=

    Mark Rae Guest

    Mark Rae, Aug 1, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    642
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,358
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    561
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    753
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    423
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page