DateTime serialization best practices in .NET 3.5

0 votes

Some years ago, I had followed this MSDN article on DateTime usage best practices for building a .Net client on .Net 1.1 and ASMX web services, with SQL 2000 server as the backend. I can still remember all the serialization issues I had with DateTime and the testing effort it took for servers across different time zones.

Does anyone know of any similar best practices document available for new technologies like WCF and SQL server 2008, especially with the addition of new datetime types for storing time zone aware info.

Environment:
1. SQL server 2008 on Pacific Time.
2. Web Services layer on a different time zone.
3. Clients could be using .Net 2.0 or .Net 3.5 on different time zones. (But, if it makes it any easy, we can just force everyone to upgrade to .Net 3.5.)

Any good suggestions/best practices for the data types to be used in each layer?

Dec 17, 2018 in Database by Bharani
• 4,550 points
59 views

1 answer to this question.

0 votes
One of the best ways to do this is by always passing the object as UTC, and converting to local time on the clients' side. That way, there is a common reference point for all clients.
You can call ToUniversalTime on the DateTime object for converting it to UTC. Then, when on the clients, just call ToLocalTime to get it in their respective current time zone.

Note: Clients will receive the datetime kind as Unspecified. So, doing DateTime.SpecifyKind(myUtcTime, DateTimeKind.Utc) instead of ToUniversalTime could be a better approach.
answered Dec 17, 2018 by DataKing99
• 8,130 points

Related Questions In Database

0 votes
1 answer

Database Repair Options in Cassandra

Anti Entropy: Anti-entropy Repair is a process of ...READ MORE

answered Jun 28, 2018 in Database by kurt_cobain
• 9,240 points
121 views
0 votes
1 answer

Logging Levels in Cassandra

ALL: All levels including custom levels TRACE: Designates finer-grained informational ...READ MORE

answered Jun 28, 2018 in Database by shams
• 3,580 points
32 views
0 votes
2 answers

Durable Writes in Cassandra

When Cassandra write: 1. memtable (in memory) 2. commit ...READ MORE

answered Nov 25, 2018 in Database by Amit
• 180 points
1,152 views
0 votes
1 answer

Standalone Mode in Hbase

It is a default mode of HBase. ...READ MORE

answered Jul 11, 2018 in Database by kurt_cobain
• 9,240 points
45 views
0 votes
1 answer

How to convert datetime.date to UTC timestamp in Python

In Python 3 (< 3.3) From the docs ...READ MORE

answered Oct 31, 2018 in Python by Priyaj
• 56,520 points
1,890 views
0 votes
1 answer

Using unserialize in PHP throws the same error repeatedly

I googled 'Node no longer exists', and ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,130 points
130 views
0 votes
1 answer

python 'x days ago' to datetime

You just need a timedelta and try ...READ MORE

answered Feb 26 in Python by SDeb
• 13,160 points
91 views
0 votes
1 answer

Indexes in Database

The index is a data structure that ...READ MORE

answered Aug 20, 2018 in Database by DataKing99
• 8,130 points
49 views
0 votes
1 answer

Atomicity and Aggregation in Database

Atomicity is the condition where either all the ...READ MORE

answered Aug 22, 2018 in Database by DataKing99
• 8,130 points
125 views