I'm sending data from a winforms project to a Sql Server database by turning the object data into XML and then parsing it on the SQL side out to the target tables.
This works fine, except for an issue with dates.
Often I am not interested in the time part of a datetime value, just the date, so have dates basically entered in the front end as '2021-08-05 00:00:00'.
When I create the XML, it becomes:
2021-08-05T00:00:00+01:00
(+01:00 because I am in the UK, and we are currently an hour ahead of UTC/GMT).
But when that ends up in the Date field in the relevant table, the value has slipped back to 2021-08-04, i.e. yesterday.
Is there a way to control how the XML is generated to stop it adding the time zone difference?
The classes for the data objects are all tagged with [Serializable]
at the top. I don't have any special attributes on the date properties themselves.
This is the c# code that converts the object into XML, though I don't think there is a problem here per se (and I probably nicked it from some helpful post up here anyway!):
public static string ConvertToXmlDoc(object dataModeldata)
{
Type modelType = dataModeldata.GetType();
var writer = new XmlSerializer(modelType);
StringWriter sw = new StringWriter();
writer.Serialize(sw, dataModeldata);
string xmlDoc = sw.ToString();
return xmlDoc;
}