Date Format - best way of converting a string into a date format

Discussion in 'ASP .Net' started by Brian Candy, Feb 18, 2004.

  1. Brian Candy

    Brian Candy Guest

    I am guessing that this must be a common question, but I just can't
    find a simple solution for it by searching the newsgroups. I have a
    Text Box with a date in a UK format. The format has been verified and
    is legal. Now all I want to do is pop it into an SQL field. Debugging
    on my local machine everything works with the following:

    dDOB = CDate(txtDOB)
    Row.Item("DOB") = dDOB

    But when deployed this would fail because CDate requires MM/DD/YYYY
    rather than DD/MM/YYYY.

    In short I want to display and collect dates from users with the date
    format DD/MM/YYYY which is fine on my local machine, but not on my
    server farm. If I use string manipulation to solve this, it works on
    my server farm but not on my local machine. I could write some
    un-elegant code to solve this, but I am convinced there must be a
    simple way of overcoming this problem.

    Thanks in advance for any help.

    Brian Candy
     
    Brian Candy, Feb 18, 2004
    #1
    1. Advertising

  2. Hi, Brian Candy,

    You can try the static method ParseExact on the System.DateTime structure:

    http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDateTimeClassParseExactTopic.asp

    And then pass the DateTime value as a parameter to insert it into the DB.

    Greetings
    Martin
    "Brian Candy" <> wrote in message
    news:...
    > I am guessing that this must be a common question, but I just can't
    > find a simple solution for it by searching the newsgroups. I have a
    > Text Box with a date in a UK format. The format has been verified and
    > is legal. Now all I want to do is pop it into an SQL field. Debugging
    > on my local machine everything works with the following:
    >
    > dDOB = CDate(txtDOB)
    > Row.Item("DOB") = dDOB
    >
    > But when deployed this would fail because CDate requires MM/DD/YYYY
    > rather than DD/MM/YYYY.
    >
    > In short I want to display and collect dates from users with the date
    > format DD/MM/YYYY which is fine on my local machine, but not on my
    > server farm. If I use string manipulation to solve this, it works on
    > my server farm but not on my local machine. I could write some
    > un-elegant code to solve this, but I am convinced there must be a
    > simple way of overcoming this problem.
    >
    > Thanks in advance for any help.
    >
    > Brian Candy
    >
     
    Martin Dechev, Feb 18, 2004
    #2
    1. Advertising

  3. Brian Candy

    Janaka Guest

    Hey Brian,

    Sounds like your web server farm is set up using US settings. You can set
    the localisation to uk formatting by doing one of two things:

    1) Setting the locale identifier in the page directive: <%@ Page
    LCID="2057" Language="VB" %>
    2057 is the locale for UK. This will work on the page in question.

    2) Setting the culture for the entire site. This has to be done in
    web.config by applying the following tag within <system.web>
    <globalization culture="en-GB" uiCulture="en" ></globalization>

    Hope that helps.

    Janaka



    "Brian Candy" <> wrote in message
    news:...
    > I am guessing that this must be a common question, but I just can't
    > find a simple solution for it by searching the newsgroups. I have a
    > Text Box with a date in a UK format. The format has been verified and
    > is legal. Now all I want to do is pop it into an SQL field. Debugging
    > on my local machine everything works with the following:
    >
    > dDOB = CDate(txtDOB)
    > Row.Item("DOB") = dDOB
    >
    > But when deployed this would fail because CDate requires MM/DD/YYYY
    > rather than DD/MM/YYYY.
    >
    > In short I want to display and collect dates from users with the date
    > format DD/MM/YYYY which is fine on my local machine, but not on my
    > server farm. If I use string manipulation to solve this, it works on
    > my server farm but not on my local machine. I could write some
    > un-elegant code to solve this, but I am convinced there must be a
    > simple way of overcoming this problem.
    >
    > Thanks in advance for any help.
    >
    > Brian Candy
    >
     
    Janaka, Feb 18, 2004
    #3
    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. blrmaani
    Replies:
    4
    Views:
    14,144
    Karthik
    Apr 27, 2004
  2. deepak
    Replies:
    0
    Views:
    424
    deepak
    Feb 14, 2008
  3. tekion
    Replies:
    4
    Views:
    740
    tekion
    Dec 21, 2009
  4. Leif Wessman
    Replies:
    4
    Views:
    110
    Anno Siegel
    Aug 29, 2004
  5. Replies:
    1
    Views:
    132
    Mark Lawrence
    Oct 1, 2013
Loading...

Share This Page