N
nobody
I know that given a FormatString and a DateTime you can use
DateTime.ToString(...) to convert the DateTime to a String. My question is
how can you turn that around? Given a String and a FormatString, how can
you convert the String back to a DateTime? DateTime.Parse(...) doesn't use
the FormatString.
Now admitedly, if the format string is just "MM", it can't be done. But if
the format string is "yyyyMMdd", or "ddMMMyyyy hhmmsst", it should be able
to be done. DateTime.Parse(...) is pretty good at figuring out the format
of the String, but it chokes on dates in the format "yyyymmdd" which is a
pretty common storage format for dates. I can't just parse it myself (ok, I
could, but it would be more work than I'm willing to (aka "being paid to")
do.) The Format Strings are entered into the program by the users and could
be ANYTHING. I'd like to at least make a good attempt to read the DateTime
data using the user's format string (the data was written out using their
format string using DateTime.ToString(FormatString).
Currently I'm writing the data out using DateTime.ToString(...) and reading
it back in with DateTime.Parse(...). But if their format string is
"yyyyMMdd", then it writes it out fine, but chokes reading it back in.
Any help on this matter is greatly appreciated. Thanks!
-----
DateTime.ToString(...) to convert the DateTime to a String. My question is
how can you turn that around? Given a String and a FormatString, how can
you convert the String back to a DateTime? DateTime.Parse(...) doesn't use
the FormatString.
Now admitedly, if the format string is just "MM", it can't be done. But if
the format string is "yyyyMMdd", or "ddMMMyyyy hhmmsst", it should be able
to be done. DateTime.Parse(...) is pretty good at figuring out the format
of the String, but it chokes on dates in the format "yyyymmdd" which is a
pretty common storage format for dates. I can't just parse it myself (ok, I
could, but it would be more work than I'm willing to (aka "being paid to")
do.) The Format Strings are entered into the program by the users and could
be ANYTHING. I'd like to at least make a good attempt to read the DateTime
data using the user's format string (the data was written out using their
format string using DateTime.ToString(FormatString).
Currently I'm writing the data out using DateTime.ToString(...) and reading
it back in with DateTime.Parse(...). But if their format string is
"yyyyMMdd", then it writes it out fine, but chokes reading it back in.
Any help on this matter is greatly appreciated. Thanks!
-----