Reputation: 3328
My problem is that i am not able to convert the US date value into british format. The TryParse condition is always coming out as false and thus the outputValue is never filled up.
Is there something wrong with the implementation ? Please pin point or suggest better alternative. Thanks.
string filterValue = "12/22/2011"
string outputValue = ""
DateTime dt;
string strCulture = "en-GB";
CultureInfo ci = new CultureInfo(strCulture);
if (DateTime.TryParse(filterValue, ci, DateTimeStyles.AdjustToUniversal, out dt))
outputValue = dt.ToString("d", ci);
Upvotes: 0
Views: 745
Reputation: 22448
You use British culture for parsing date in US format. Use code below.
string filterValue = "12/22/2011";
DateTime dt;
string outputValue = "";
if (DateTime.TryParse(filterValue, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AdjustToUniversal, out dt))
{
outputValue = dt.ToString("d", CultureInfo.GetCultureInfo("en-GB"));
}
Upvotes: 1