First of all, I don't think you really need to "convert". You should not work with string representation of data instead of data. In your case, you should work with
System.DateTime
instead of strings representing it. Only of you need to show the data on screen, you use one of
System.DateTime
methods, and only then you choose the format. Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[
^], read on every
ToString
method.
For formatting, please see
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[
^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[
^].
Another way of formatting is through choosing appropriate
culture, see, for example:
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[
^].
In rare cases, you need to interpret string from certain format. Even this can be simplified, because, say, in SQL you should better use
DATE
type not tied to a particular format, in contrast to strings. But in case you need, you should
parse a string into
System.DateTime
, so see all the methods
Parse
,
ParseExact
,
TryParse
and
TryParseExact
.
Of course, using the methods referenced, you can "convert" as you wanted, but "convert" approach is wrong.
—SA