Results 1 to 5 of 5

Thread: DateTime conversion

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    DateTime conversion

    How to convert this date format "september 29, 2008 - 13:00:07 " into "9/29/2008 1:00:07 PM"?
    Visual Studio.net 2010
    If this post is useful, rate it


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

    Re: DateTime conversion

    To convert a string representation of a date into a Date object you call Date.ParseExact or, if there's a chance it might not be valid, Date.TryParseExact. To convert a Date object into a string in a specific format you call ToString and specify that format. MSDN describes all the standard and custom format strings available to you for converting between Strings and Dates in each direction. I'll leave it to you to look that up because it will benefit you to see all of what's available rather than just a single solution to a single problem. Once you've read that documentation you'll never have to ask for a date format again.
    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
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: DateTime conversion

    Quote Originally Posted by jmcilhinney
    MSDN describes all the standard and custom format strings available to you for converting between Strings and Dates in each direction.
    yep.. i started referring when this date format banged my head,,.
    but immediately i cant get the solution. so went through string manipultaion
    anyway thanks jmc..
    Visual Studio.net 2010
    If this post is useful, rate it


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

    Re: DateTime conversion

    Well, as I said, MSDN describes all the custom format strings available so I don't know where you were looking. That original string is "MMMM d, yyyy - HH:mm:ss" and the final string is "M/dd/yyyy h:mm:ss tt". Simple.
    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

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: DateTime conversion

    @vijy - you read this http://msdn.microsoft.com/en-us/library/az4se3k1.aspx and did not find the answer????

    Code:
            Dim ds As String = "september 29, 2008 - 13:00:07"
            ds = ds.Replace("-"c, " "c)
            Dim dt As DateTime
            dt = DateTime.Parse(ds)
            Debug.WriteLine(dt.ToString)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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