Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:10:52+00:00 2026-06-10T09:10:52+00:00

How can I convert the string to datetime. I have following string: 08/19/2012 04:33:37

  • 0

How can I convert the string to datetime. I have following string:

08/19/2012 04:33:37 PM

I want to convert above string to following format date:

MM-dd-yyyy

and

dd/MM/yyyy HH:mm:ss

I have been trying to convert using different technique and using following:

DateTime firstdate = DateTime.Parse(startdatestring);

It shows following error

String was not recognized as a valid DateTime.

I have search for it and couldn’t get exact solution and also try using different format for datetime. Please how can I convert above string to above date format

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:10:53+00:00Added an answer on June 10, 2026 at 9:10 am

    You need to parse the string first – you have missed out the AM/PM designator. Take a look at Custom Date and Time Format Strings on MSDN:

    DateTime firstdate = DateTime.ParseExact(startdatestring, 
                                             "MM/dd/yyyy hh:mm:ss tt",
                                             CultureInfo.InvariantCulture);
    

    Then you can format to a string:

    var firstDateString = firstdate.ToString("MM-dd-yyyy");
    

    Which you may also want to do with InvariantCulture:

    var firstDateString = firstdate.ToString("MM-dd-yyyy", 
                                             CultureInfo.InvariantCulture);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date/time string like 2012-01-13 04:37:20 but I want to convert it
I have the following function DateTime fromDateParam = DateTime.ParseExact(Convert.ToString(DateTime.MinValue),dd.MM.yyyy HH:mm:ss,null); It says input string
I have a datetime string being provided to me in the following format: yyyy-MM-dd
I have the following code to convert different string representations of date/datetime into timestamp
How can I convert a string 08:00 to a DateTime datatype? Im trying to
Can anyone please help me how to convert string to date I have 3
I have a string I need to convert back to a date. I can
I have a DateTime string in 24 HOURS format .. 2009-12-31T23:59:59 I want it
I am trying to convert the following string to a DateTime value in c#:
I have the following code: DateTime pickerDate = Convert.ToDateTime(pickerWakeupDate.SelectedDate); string enteredStr = pickerDate.ToShortDateString() +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.