Can anyone please advise on how to work around this issue? I need to convert DateTime into milliseconds since epoch and store that returned value in the database. The issue I am running into is that no matter what data type I specify the field to be, Azure automatically stores the returned value in actual date format - i.e., I get returned 1613800800000 correctly as I have it coded to do, but always gets stored in the database in this format no matter what, "Feb 20 2021 1".
protected void testButton_Click(object sender, EventArgs e)
{
TimeSpan reversion = new TimeSpan(0, 0, 0);
DayOfWeek weekday = DateTime.Today.DayOfWeek;
if(weekday == DayOfWeek.Tuesday)
{
DateTime utcTime = DateTime.UtcNow;
TimeZoneInfo centralZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
DateTime centralTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, centralZone).AddDays(-3);
DateTime centralTimeConvert = TimeZoneInfo.ConvertTimeFromUtc(utcTime, centralZone).AddDays(-3);
centralTime = centralTime.Date + reversion;
centralTimeConvert = centralTimeConvert.Date + reversion;
var centralTimeMilliseconds = centralTimeConvert.ToUniversalTime().Subtract(
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
).TotalMilliseconds;
System.Data.SqlClient.SqlConnection connect = new System.Data.SqlClient.SqlConnection(masterConnectionString);
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
command.CommandType = System.Data.CommandType.Text;
command.CommandText = @"INSERT INTO StartEndTimes (StartTimeMilliseconds, StartTime) VALUES (@StartTimeMilliseconds, @StartTime)";
command.Parameters.AddWithValue("@StartTime", centralTime);
command.Parameters.AddWithValue("@StartTimeMilliseconds", centralTimeConvert);
command.Connection = connect;
connect.Open();
command.ExecuteNonQuery();
connect.Close();
responseLabel.Text = centralTimeMilliseconds.ToString().Truncate(13);
}
else
{
}
}
I've tried specifying the data type as int, char, etc., and every other option so I'm hoping there's a way to hard code the storage format or some other way to stop the auto date formatting.