Results 1 to 4 of 4

Thread: How to convert "Wed Mar 08 21:21:38 2006" into a DateTime?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    How to convert "Wed Mar 08 21:21:38 2006" into a DateTime?

    How can I convert a string such as "Wed Mar 08 21:21:38 2006" into a DateTime?

    What I'm trying to do is reformat a date in that string into a date that looks like "03/08/06 21:21:38".
    Brandon S Davids

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

    Re: How to convert "Wed Mar 08 21:21:38 2006" into a DateTime?

    VB Code:
    1. Dim myDateString As String = Date.ParseExact("Wed Mar 08 21:21:38 2006", "ddd MMM dd HH:mm:ss yyyy").ToString("MM/dd/yy HH:mm:ss")
    This creates a Date object that corresponds to the string in the specified format, then creates another String that corresponds to that date in the second format. Doing it in one line like this loses the Date object. If you want to keep it you could separate the operation into multiple lines. That way you can use the date object for other purposes, like calculations.
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Re: How to convert "Wed Mar 08 21:21:38 2006" into a DateTime?

    Thank you. That's exactly what I was looking for.
    Brandon S Davids

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

    Re: How to convert "Wed Mar 08 21:21:38 2006" into a DateTime?

    Cool. Don't forget to resolve your thread from the Thread Tools menu.
    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