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 da
DateTime
doesn't store dates in any specific format - it uses an internal representation (what exactly shouldn't matter).
After parsing the string to a DateTime
, there is no inherent format there. There is only a format when you output the value. What you see in the debugger is simply a conversion to a string using your system settings.
If you want to format the DateTime
, use ToString
with a format string:
dt.ToString("dd/MM/yyyy");
The converse also applies - if you need to parse the string unambiguously, use ParseExact
or TryParseExact
(both static members of of DateTime
):
DateTime dt;
if(DateTime.TryParseExact(txtDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture,
DateTimeStyles.None, out td))
{
// Valid date used in `txtDate.Text`, use dt now.
}
Read about custom and standard Date and Time format strings.