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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:01:58+00:00 2026-05-18T20:01:58+00:00

I have a Textbox in which the user is supposed to enter a date

  • 0

I have a Textbox in which the user is supposed to enter a date in the format dd/mm/yyyy, this date is stored as yyyy/mm/dd in the database.

So I want the user to enter the date in dd/mm/yyyy format and later I want to convert to yyyy/mm/dd so that I can query database.

How can I convert the user input date dd/mm/yyyy to yyyy/mm/dd?

  • 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-18T20:01:59+00:00Added an answer on May 18, 2026 at 8:01 pm

    Quick and maybe dirty:

    string reformattedDate = DateTime.ParseExact(textBox1.Text, "dd/MM/yyyy", null).ToString("yyyy/MM/dd");
    

    This, of course, assumes that the content of the Textbox will always be in the assumed format, so their should be checks in before to ensure that. There’s also the much safer way which does not need additional checks:

    DateTime result;
    if(DateTime.TryParseExact(textBox1.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out result)
    {
        // Here you can safely use result
        string reformattedDate = result.ToString("yyyy/MM/dd");
    } else {
        // Screw the user
    }
    

    This will try to parse the content of the Textbox and return it to your via the out result, if successful, it will return true. Otherwise you can rest assured that the input was either not in the assumed format, or not a valid Date.

    Please also be aware that ParseExact will throw an ArgumentNullException or an ArgumentException if the conversion fails.

    • MSDN Article for ParseExact
    • MSDN Article for TryParseExact

    I have a text box in which the user is supposed to enter a date in dd/mm/yyyy format, this date is stored as yyyy/mm/dd in the database.

    The obvious answer to this is: use a DateTimePicker and a parameterized query before wrestling with a string conversion. It will save you a lot of headache in the long run.

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

Sidebar

Related Questions

I have a Textbox in which the user is supposed to enter a date
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a textbox.T he user will be entering entering a number in this
I have a user table in my database which contains two columns FirstName and
I am having a Password textbox which will have empty value. when the user
I have a webpage in which I let user to enter the contents, even
In my app, I want to be able to have the user enter their
I have some C# / asp.net code I inherited which has a textbox which
I have a numeric textbox in C# .NET which is nothing more than a
I have UserControl which contains a TextBox and a Button control. The Button opens

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.