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

  • SEARCH
  • Home
  • 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 7874329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:47:08+00:00 2026-06-03T02:47:08+00:00

I am trying to convert a string into a DateTime and change its format

  • 0

I am trying to convert a string into a DateTime and change its format from 05/06/2012 12:00:00 to 2012-06-05 12:00:00.000 to search in the database (SQL Server 2008 R2) DATETIME column type. The original date is coming from a calendar!

I tried this:

string Datereturn = row.Cells[9].Text; 

DateTime dategiven = DateTime.ParseExact(Dategiven, 
             "YYYY-MM-DD hh:mm:ss[.nnn]", CultureInfo.InvariantCulture);

but it pops an error of invalid datetime

  • 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-03T02:47:10+00:00Added an answer on June 3, 2026 at 2:47 am

    To parse 05/06/2012 12:00:00:

    DateTime dategiven = DateTime.ParseExact(Dategiven, 
             "dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture);
    

    To get a different formatted string:

    string newFormat = dateGive.ToString("yyyy-MM-dd hh:mm:ss");
    

    I suggest reading Custom Date and Time Format Strings on MSDN.

    Also the different between parsing and formatting (in regards to DateTime):

    • Parsing means taking a string representing a datetime and getting a DateTime object from it

    • Formatting a DateTime is taking a DateTime object and getting a string from it, formatted as needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert a string into date time format. DateTime.Parse(tempfrmBankDetails.dgvBankDetails.SelectedRows[0].Cells[PaymentDate].Value.ToString(),null); This is
I'm trying to convert a string into money format using this function , and
I am trying to convert a string into datetime with the following C# code,
I am trying to convert a string of the below format dd/MM/yyyy hh:mm:ss.fff into
I'd like to convert a datetime format string like %m/%d/%y %H:%M into a regular
I'm trying to convert a string from a Twitter API result into an NSDate
I'm trying to convert a string into a date format My string looks like
I am trying to convert a string value into a name of an attribute
I'm trying to convert the String \something\ into the String \\something\\ using replaceAll ,
i am trying to convert a LPCSTR string into LPCTSTR string. i want to

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.