Results 1 to 5 of 5

Thread: [02/03] Changing a string to a date

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    40

    [02/03] Changing a string to a date

    I'm using VB.NET 2003 version.
    When reading a date from a file it is provided to VB as a string, right? So I have "dateShown" as the variable that the line from the file is stored too. How can I convert the data in the string into a date?
    Last edited by Hack; Mar 31st, 2006 at 07:43 AM. Reason: Added version to thread title

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Changing a string to a date

    The handy search function on this forum will pull several examples, dont forget that its there...

    http://www.vbforums.com/search.php?q...0&saveprefs=1&

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [02/03] Changing a string to a date

    I've edited your thread title to include the version that you specified in your message body. This helps people that want to help you know what sort of coding advice to provide.

    Please use the radio buttons provided to specify what version you are using when creating new threads in the future.

    Thanks.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    40

    Re: [02/03] Changing a string to a date

    In all of the examples I find it has an exact date converted into an exact date of a different format. If I don't know the exact date, because I am reading it from a file, how can I still change it to the format I want it to be in?
    Thanks

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Changing a string to a date

    A string is a string is a string. You pass the string you read from the file to whatever method you are using. You can use Parse or ParseExact. If the string contains a date in one of the recognised standard formats then use Parse. If it contains a known, non-standard format then use ParseExact. If you have no idea what format it will be in then you have a problem. You can use Parse and catch any exception that might be thrown, then try ParseExact with some likely alternatives but generally speaking data to be read by computer programs should have some consistent structure to it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width