One of the nicer things about the .net framework is its support for cultures, if you're running on a UK machine dates are handled in UK format, if you're in France date displays will display Lundi instead of Monday. By using satellite assemblies for string resources your software can use culture specific information with no extra work and if you want to do the same in asp.net then components like Localizer will do the work for you. But there's a little problem...
I recently produced an appointment calendar for the wife so she can allow her clients to see her availability and book training days. This works by pulling her appointments out of a database then by using the DayRender event I can override how a day is shown on the ASP.Net Calendar control. So as each day is rendered I want to look in the DataSet I pulled back at the start of the page to see if this day is free or booked (after all you don't want to issue a SQL command for every day, that's just not scalable).
To look inside the DataSet I use the filter property. My first attempt looked something like this;
private void calendar_OnDayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
string dateFilter = String.Format("appointmentDate >= #{0:d}# AND appointmentDate < #{1:d}#",
e.Day.Date,
e.Day.Date.AddDays(1));
DataRow[] rows = calendarData.Select(dateFilter);
if (rows.Length != 0)
{
}
}
This didn't work once it got to 13 January. I'd made a bad assumption. Filtering datasets use a pseudo SQL language and it's not culture sensitive, so when the filter sees a date like 13/1/2004 it assumes the first part is a month and throws an error because there is no month 13. So in order to ensure your filter will work you need to publish your dates in American format by changing the filter string to use the US culture by specifying the culture in the String.Format you use to build the filter;
System.Globalization.CultureInfo usCulture = new System.Globalization.CultureInfo("en-us");
string dateFilter = String.Format(usCulture
"appointmentDate >= #{0:d}# AND appointmentDate < #{1:d}#",
e.Day.Date,
e.Day.Date.AddDays(1));