views:

171

answers:

4

Hi,

what things do I have to consider when dealing with datetime in a asp.net web application?

I am also using sql server.

How can I ensure I don't run into problems with dates? (don't want to release it and THEN deal with it hehe)

+2  A: 

If you are also dealing with timezones you will want to take into account the offset from GMT - that would be the best is to record GMT time in your tabes and then you can figure for anyone in any time zone the right time

It really depends on the usage of the time and date

codemypantsoff
+1  A: 

Always consider culture when parsing dates, in America we do MM/DD/YYYY, but overseas it is usually DD/MM/YYYY.

The DateTime class has an overload to take in the expected culture. Use it.

FlySwat
+1  A: 

If your users are all in the same time zone and country, the answer is not much... But if you have the slightest inkling or know that you'll have users spanning time zones and different countries, there are a couple of items that really stand out.


First, store all of your date time values in the database as GMT Time. When they get displayed to the user, you can figure out the offset from that.

Second, different countries format dates differently. Its almost every country (dd-mm-yyyy) vs the U.S. (mm-dd-yyyy) on this one. You'll want to make sure that you allow for the UI to be localized accordingly.

Third, if you use or may use JavaScript in your web application, consider searching for Date.js on Google as you'll need a some special scripting for handling the different cultures date settings.

RSolberg
A: 

It's a really (really) broad topic. But, if you are dealing with different time zones, different cultures and different languages, you could consider sticking to the ISO Standard for date and time representation. Also, it's better to store everything in the same time zone, all UTC for example. Here is a great article about all things datetime related in technet. There are also some new date time data types in SQL Server 2008 you might be interested in.

JP Alioto