Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

ASP.Net and SQL Server Globalization - Setting Culture for Date and Time

· 0 comments

This is one of the initial difficulties I found dealing with date and time for websites with cultures set to anything but the default. No problem with US formatted dates.  However, with British formatted dates for example, you have to spend a lot of time formatting your strings within ASP.Net and your SQL server stored procedures. However, there is a way to do this as if you are programming with the default date and time format.  Here’s how…

 


1.       Connect to your server and expand Security node.


2.       Expand Logins node and locate your user.


3.       Right-click the user and click properties.


4.       Find default language and set to your language.  For example, I work mostly with British format dates (dd/mm/yyyy) so I set it to “British English”.






5.       In your website’s web.config, add the following entry under the <system.web> node.

 

<globalization culture="en-GB"/>

 

For other supported cultures go to http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx

 

Now, sql server will always expect your dates to be “en-GB” formatted or whatever culture you have set it to be.  No need to explicitly convert your date strings in ASP.Net or SQL Server.

 

 

Recent Posts

About Me

Alain Rivas
A software / web developer by profession.
A Born-Again Christian by Faith.
A father of two (with one on the way).
A husband of one.
Once a radio disc jockey for eight years.
Now a geek glued to his computer.
View my complete profile