Wednesday, 15 September 2010

Converting a date string in C# -



Converting a date string in C# -

i have date string format "dd.mm.yyyy" (eg. "01.02.2004") , want convert "yyyy-mm-dd" string.format(...) or datetime.parseexact(...) or whatelse. exceptions. usage of next code doesn't work:

string datestring = "01.02.2004"; datestring = string.format("{yyyy-mm-dd}", datestring);

what wrong that? there alternative datetime.parseexact(..)?

you need create datetime object first.

try like:

datetime t = datetime.parse("01.02.2004"); string result = t.tostring("{yyyy-mm-dd}", cultureinfo.invariantculture);

c# date datetime string-formatting

No comments:

Post a Comment