Click here to Skip to main content
15,911,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I trying to save record from mobile application and the format in which data is send from device is
2012-10-09T13:04:54+05:30
, and in phone service that saves the record in database i am parsing the data using DateTime.Parse
(date1)
in c#. but when data is saved in sql server it is saving 1 day back (like : if a send 10/9/2012 it saves 10/8/2012).

i tried to implement ( as my database server is in US)
TimeZoneInfo.ConvertTime(date1, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));


But it did't work for me. Can anybody suggest me what is going wrong.

Thanks
Posted

1 solution

You should be updating the time using UTC (Coordinated Universal Time)
It is the standard international time in which all timezones are expressed as offset of.
To compute local time from the UTC, add the timezone offset and then add an additional hour if daylight savings time is in effect.

To Get the Current time in UTC

C#
DateTime currentTime = DateTime.UtcNow; 

SQL 
DECLARE @currentTime datetime
SET @currentTime = GETUTCDATE() 


To convert UTC to current time
C#

DateTime currentServerTime = DateTime.UtcNow.ToLocalTime();
currentServerTime = ((DateTime) Eval("YourDate")).ToLocalTime();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900