views:

120

answers:

2
DateTime date = new DateTime(1970, 1, 15);
string sdate = date.ToString(value_i_will_forget as string,
    CultureInfo.InvariantCulture);

// some lines later

string format_string = MagicParse(sdate,
    CultureInfo.InvariantCulture);

I have an arbitrary date that I write to a string with CulturInfo.InvariantCulture. The .Net format I use - "d", for example - is now forgotten.

I do know however that the string hasn't changed, its still valid and its still with invariant culture. Im looking for the MagicParse function to extract the format string used to write the formatted date.

A: 

Unless you have a sample of dates in which the day exceeds 12, then there is no feasible way that this would ever be safe.

spender
Even though we are able to assume that the format haven't changed?
mizipzor
Even then you're not certain. A 13 can be either the day or 2013.
Carra
Example: The date is January 1st, 2001. The format strings "MM/dd/yy", "dd/MM/yy", "yy/MM/dd"... all create "01/01/01". How do you reverse engineer that?
Greg
A: 

DateTime.Parse(your_date_string, CultureInfo.InvariantInfo)
, also you can add specific DateTimeStyles in third parameter
Try this one
http://msdn.microsoft.com/en-US/library/system.globalization.datetimeformatinfo.shortdatepattern.aspx

zabulus
This doesn't give the format string used to parse the DateTime.
Greg