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.

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,660 points

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,240 points

Related Questions In Database

0 votes
1 answer

My values in my codes aren't inserted into mySQL. I input 5 but it will show 0. Any ideas?

Hello, You can refer my corresponding sample web ...READ MORE

answered Jul 13, 2020 in Database by Niroj
• 82,740 points
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

Timestamp is a synonym for rowversion, according ...READ MORE

answered Feb 16 in Database by Vaani
• 7,020 points
0 votes
1 answer

What is the best library in python to deal with excel files?

XlsxWriter and Xlwings are the best, in ...READ MORE

answered Apr 4 in Database by Edureka
• 13,640 points
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,390 points
0 votes
1 answer

How to convert to UTC timestamp in Python

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

answered Oct 31, 2018 in Python by Priyaj
• 58,080 points
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,240 points
0 votes
1 answer

python 'x days ago' to datetime

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

answered Feb 26, 2019 in Python by SDeb
• 13,300 points
0 votes
0 answers
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,240 points
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,240 points
Send OTP
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP