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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:03:43+00:00 2026-05-26T02:03:43+00:00

I am facing a small issue which i am not able after trying so

  • 0

I am facing a small issue which i am not able after trying so many things so here it goes ….. There is a text box in my page in which i am entering date and i want that date in a datetime object.

for ex :
date entd : 6 05 2020(dd/MM/yyyy) should be in same format when i am accessing it in date time object but it is getting changed to (6.05.2020ie: MM/dd/yyyy format).

i hope i am making sense here all i want is some thing like this…..

DateTime dt = convert.ToDateTime(txtDate.Text);

dt should be (11/2/2010 rather then 2/11/2010)

@oded after using the following code

DateTime sDate, eDate = new DateTime(); 

//To modify dates for our use.
DateTime.TryParseExact(txtFrom.Text, “dd/MM/yyyy”, CultureInfo.InvariantCulture, DateTimeStyles.None, out sDate);

DateTime.TryParseExact(txtFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out eDate); 

What i am getting in edate and sdate is 6 05 2020 12:00:00 AM where it should be 6/05/2020

  • 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-26T02:03:43+00:00Added an answer on May 26, 2026 at 2:03 am

    EDIT: This value: “11/2/2010” doesn’t match the format “dd/MM/yyyy”. It matches the format “d/M/yyyy” – for “dd/MM/yyyy” it should be “11/02/2010”.

    That’s why TryParseExact is failing for you. You need to pick the right format pattern.


    A DateTime value doesn’t have a format. It just represents date and time (in the ISO calendar, and possibly in different time zones, but that’s a different matter). It’s like an int – it doesn’t represent “a decimal integer” or “a hex integer” – it’s just an integer within a particular range. You can format a number as decimal or hex, but it doesn’t inherently have a format.

    It sounds like you should parse it with ParseExact to specify the format when converting from the textbox, or probably TryParseExact:

    // This is assuming you're absolutely sure of the format used. This is *not*
    // necessarily the user's preferred format. You should think about where your
    // data is coming from.
    DateTime date;
    if (DateTime.TryParseExact(text, "dd/MM/yyyy", CultureInfo.InvariantCulture,
                               DateTimeStyles.None, out date))
    {
        // Okay, successful parse. We now have the date. Use it, avoiding formatting
        // it back to a string for as long as possible.
    }
    

    You should keep that value as DateTime for all purposes except giving it back to a user – at which point you may well want to use their cultural settings.

    In particular, if you’re storing the value in a database you should not convert it to text and include it in a SQL statement – that’s asking for trouble. Instead, use a parameterized SQL statement and set it as the parameter value, still as a DateTime.

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

Sidebar

Related Questions

I am facing an small issue in my project When I am trying to
ghost noscript tag more info here I am facing exactly this issue, how shall
Here is an issue I've confronted in multiple user-facing applications: a program contains components
I am facing one small issue. I want to change the parent div style
I'm facing a weird issue. I wrote a small server in C++ that stores
Evening, I'm facing a small problem which I can't get fixed. I'm having one
I am trying to write a small php application and i am facing a
I am facing a small problem. I have a struct, which has a vector.
Here are the problems that I'm facing with a small jQuery script : In
I'm trying to develop a game and running into a small issue with NSTimer,

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.