I am trying to save a DateTime
to a database.
When I run the code from my server machine and save the date to the db, it saves the DateTime
correctly, but when I deploy the site to production, access it from my local machine, and try to save the same DateTime
, then it changes it to a diferent date and time. I guess this may be due to diferent timezones on my machine and the server machine.
I tried to convert the datetime to UTC but its not working:
DateTime OnlyStartDate = Convert.ToDateTime(app_date);
DateTime NewStartDateTime = Convert.ToDateTime(
OnlyStartDate.Add(TimeSpan.Parse(appData.start.ToString("HH:mm:ss"))));
startTime = Convert.ToString(NewStartDateTime);
This is the query in which the variable startTime is passed, which saves the wrong time to the db:
query = "Insert into [Appointments] Values('" + loc_id + "', '" + appData.titleId +
"', '" + patiant_id + "', '" + app_date + "', '" + startTime + "', '" + endTime +
"', '" + appData.providerId + "', 'enable', 'False', '" + userEmail + "', '" +
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "', '" + userEmail + "', '" +
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "', '" +
appData.statusId + "', '" + appData.userId + "','')";
DB.executeQuery(query);