Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
getting issue when save date into database.

i am getting utc time convert it into as per country time and save it and getting issues.

Exception :

Managed Debugging Assistant 'DateTimeInvalidLocalFormat' has detected a problem in 'C:\Program Files (x86)\IIS Express\iisexpress.exe'.

Additional information: A UTC DateTime is being converted to text in a format that is only correct for local times.
This can happen when calling DateTime.ToString using the 'z' format specifier,
which will include a local time zone offset in the output.
In that case, either use the 'Z' format specifier, which designates a UTC time, or use the 'o' format string,
which is the recommended way to persist a DateTime in text.
This can also occur when passing a DateTime to be serialized by XmlConvert or DataSet.
If using XmlConvert.ToString, pass in XmlDateTimeSerializationMode.RoundtripKind to serialize correctly.
If using DataSet, set the DateTimeMode on the DataColumn object to DataSetDateTime.Utc.
Posted
Comments
Sinisa Hajnal 19-Jan-15 5:51am    
Well, are you using DataSet? What have you done to try and repair it? Show the code saving into database. Did you check project properties for any locale information?
_Kapil 20-Jan-15 2:47am    
double timeZoneOffset = (double)0;
#region To get either dept timezone in minutes
timeZoneOffset = StationRemoteController.GetDepartmentTimeZoneOffsetByDeptID(Convert.ToInt32(uad.Dep_id));
#endregion


DateTime localTime = DateTime.Now.ToUniversalTime().AddMinutes(timeZoneOffset);


and finally it saving into database.

It's telling you what to do.
Quote:
This can happen when calling DateTime.ToString using the 'z' format specifier,
which will include a local time zone offset in the output.
In that case, either use the 'Z' format specifier, which designates a UTC time, or use the 'o' format string,
which is the recommended way to persist a DateTime in text.
More at - dateTimeInvalidLocalFormat MDA[^].
 
Share this answer
 
Comments
_Kapil 20-Jan-15 2:13am    
Please give me syntax convert local time format in utc format or into 'z' or 'o' fomat


my question is?
it may be new setting for datetime in vs2013....
See the "Resolution" Heading in that link.
Hi. Are you getting this error when running in visual studio or when deployed in IIS. Because even I faced same problem it was working fine when running through code but once deployed in IIS date problem was there. I just set the datetime standards in IIS and later it worked fine.
 
Share this answer
 
Comments
_Kapil 20-Jan-15 2:11am    
I am getting issues when running code on my system.

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