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,660 points
944 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,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,880 points
888 views
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

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

answered Feb 16, 2022 in Database by Vaani
• 7,060 points
4,555 views
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, 2022 in Database by Edureka
• 13,670 points
3,408 views
0 votes
0 answers

DateTime2 vs DateTime in SQL Server

Which one: datetime datetime2 is the recommended way to store date and ...READ MORE

Aug 14, 2022 in Database by Kithuzzz
• 38,010 points
470 views
0 votes
0 answers

Calculate time difference in minutes in SQL Server

I require the minutes-based time difference between ...READ MORE

Aug 13, 2022 in Database by Kithuzzz
• 38,010 points
1,094 views
0 votes
0 answers

How can I select the first day of a month in SQL?

I only need to choose the given ...READ MORE

Aug 14, 2022 in Database by Kithuzzz
• 38,010 points
455 views
0 votes
0 answers

SQL query to insert datetime in SQL Server

Using the SQL query below, I want ...READ MORE

Aug 29, 2022 in Database by Kithuzzz
• 38,010 points
2,000 views
0 votes
0 answers

How to return only the Date from a SQL Server DateTime datatype

SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part ...READ MORE

Sep 6, 2022 in Database by Kithuzzz
• 38,010 points
430 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,240 points
757 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,240 points
2,665 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP