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 1097003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:21:57+00:00 2026-05-17T00:21:57+00:00

I want to convert text to datetime but having error.My text box value is

  • 0

I want to convert text to datetime but having error.My text box value is in format dd/MM/yyyy
String was not recognized as a valid DateTime.

myFtMaster.GENTRTYDATEFROM =Convert.ToDateTime(txtTreatyPeriodfrom.Text.ToString());

My business object ‘gentrtydatefrom’ datatype is DateTime. Also what is the best way to avoid these type of errors without using a Try catch block.

  • 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-05-17T00:21:58+00:00Added an answer on May 17, 2026 at 12:21 am

    You either specify a culture that uses that specific format:

    myFtMaster.GENTRTYDATEFROM = Convert.ToDateTime(
      txtTreatyPeriodfrom.Text, CultureInfo.GetCulture("en-GB")
    );
    

    or use the ParseExact method:

    myFtMaster.GENTRTYDATEFROM = DateTime.ParseExact(
      txtTreatyPeriodfrom.Text, "dd/MM/yyyy", CultureInfo.Invariant
    );
    

    The ParseExact method only accepts that specific format, while the Convert.ToDateTime method still allows some variations on the format, and also accepts some other date formats.

    To catch illegal input, you can use the TryParseExact method:

    DateTime d;
    if (DateTime.TryParseExact(txtTreatyPeriodfrom.Text, "dd/MM/yyyy", CultureInfo.Invariant, DateTimeStyles.None, out d)) {
      myFtMaster.GENTRTYDATEFROM = d;
    } else {
      // communcate the failure to the user
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert a string to formatted text in C# in WPF application,
I want to convert my text into HTML format, it would be just like
How to convert C# datetime to MySql Datetime format. I am getting value from
How to convert text value into date Textbox1 column value = 31/12/2009 (dd/MM/yyyy) Tried
I want to convert string date to system datetime in C#. The user enters
I have a MySql datetime value like 2012-04-17 20:48:29. I want to convert this
I have some html files that I want to convert to text. I have
I have a TextBoxD1.Text and I want to convert it to an int to
I want to use the Discount C-library to convert Markdown text into HTML. I
I have a text document (.txt). I want to convert it to an image

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.