convert string to datetime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • satiss7pwr
    New Member
    • Jan 2010
    • 41

    #1

    convert string to datetime

    i have string like "30/03/2010 12:03:15:PM"
    i want to covert in date time how it possible?
    to convert i got this error "String was not recognized as a valid DateTime."
    thanks
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

    #2
    Try: Date.Parse("30/03/2010 12:03:15:PM")

    Happy Coding,
    CroCrew~

    Comment

    • satiss7pwr
      New Member
      • Jan 2010
      • 41

      #3
      hey i have string variable like string ctime="30/03/2010 12:03:15:PM";
      now tell me how to i create datetime varable ,pls tell me im new

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        All the information you need on the DateTime structure and any other .NET classes, structures, and controls can be found in the MSDN Library. This resource should get you pointed in the right direction....th ere are multiple articles on the DateTime structure there. I recommend bookmarking the MSDN Library and using it as your primary resource when developing in .NET.

        I think that you would be most interested in check out the DateTime.Parse method and the DateTime.TryPar se method.

        Please take the time to research the problem before you post your question. The experts here are more than willing to help you with a specific problem but you have to do your part to learn the basics. Please take the time to read over the posting guidelines specifically the section on Before you post your question.

        Comment

        • satiss7pwr
          New Member
          • Jan 2010
          • 41

          #5
          i had try all things but i got every time only one error
          String was not recognized as a valid DateTime.
          i have string ctime="30/03/2010 12:03:15:PM";
          pls give me code

          Comment

          • CroCrew
            Recognized Expert Contributor
            • Jan 2008
            • 564

            #6
            Hello satiss7pwr,

            Can you please post your code so we can see what your doing. Then we could provide you with a solution.

            CroCrew~

            Comment

            • satiss7pwr
              New Member
              • Jan 2010
              • 41

              #7
              string time is come from database n i ma matching this string with current time
              just give conversion code to me

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                I don't think that this is a valid date/time string format:

                "30/03/2010 12:03:15:PM"

                There should not be ":PM"

                Remove the : before the PM and see if it works.

                Comment

                • CroCrew
                  Recognized Expert Contributor
                  • Jan 2008
                  • 564

                  #9
                  Originally posted by satiss7pwr
                  ...just give conversion code to me
                  I am going to hold off on providing you with help till I see the code that you’re trying to use. I am not going to keep throwing darts at a wall till you tell me it works.

                  Again, please post your code so that we can look at it and see what you’re trying to do. Then we can review and provide you with what we think would be your best solution to your problem.

                  Best of luck,
                  CroCrew~

                  Comment

                  • satiss7pwr
                    New Member
                    • Jan 2010
                    • 41

                    #10
                    my string is like this "30/03/2010 12:03:15:PM" n i got one suggestion that remove colon from before PM like this "30/03/2010 12:03:15 PM"
                    again i got this error "String was not recognized as a valid DateTime"
                    No budy Here to solve this small problem??

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Please do as CroCrew asked...please post the code that is causing the problem.
                      We cannot help you if you do not show us what you've done.

                      -Frinny

                      Comment

                      Working...