Question

I am wondering the best place in my web application tiers to user regional settings to format date column output from a database results query.

I can get the regional settings from the HttpContext.Request and pass this as a string to the Business Layer and then use System.Globalisation in the Business Object Layer to create a DateTimeFormatInfo object.

ie. DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture(cultureString).DateTimeFormat;

The business layer fetches the data from a Data Access Layer and using a LINQ query selector the date column can be formatted with the dtfi object above.

However I am wondering if I really should be passing a string with the language-culture to the business layer and should instead load up another anonymous type with the data returned from the business layer and add the date formatting in the controller.

This would avoid the situation of a WPF app passing the culture info of the executing threa to the same call in the Business layer.

Was it helpful?

Solution

Personally, I prefer to deal with all the culture stuff as soon as possible for input and as late as possible for output, which means in the UI and the controller code. The business layer should only concern itself with a regular DateTime object.

Culture code is messy code and it is helpful to keep that messy code in one place and not let it seep through multiple layers of your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top