Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest method to remove the Millisecond's part of a DateTime.UctNow.TimeOfDay?

Tags:

I have a theory why the following code is not producing the results I need:

 endDate = DateTime.UtcNow.AddDays(1).ToShortDateString() + " " +    
      DateTime.UtcNow.TimeOfDay.Subtract(
         new TimeSpan(0, 0, 0, 0, DateTime.UtcNow.TimeOfDay.Milliseconds));

The processor must calculate the DateTime.UtcNow.TimeOfDay.Milliseconds, and due to the time length of a single tick of the CPU (and the time to process this property and return a result), It does not denote that DateTime.UtcNow.TimeOfDay.Milliseconds will subtract the exact amount of milliseconds specified by the DateTime.UtcNow.TimeOfDay

I need to know, what is the simplest and most effective method to remove the amount of milliseconds from DateTime.UtcNow.TimeOfDay, without having to use a huge amount of processor time? This application of mine is pretty big, and this problem is pretty simple. But when this application gets deployed, there are no room for it to be unstable. This milliseconds must be trimmed because it is sent to a stored procedure in SQL Server, and this specific stored procedure does not support milliseconds on DateTimes. I also run into this problem commonly, but I normally convert the date to string (which is a cast on its own), split the string at the full stop at milliseconds, and use the index position 0 to get the time i need. Is there a shorter, more effective way?

Stability and speed is most important to me.

Thanks in advance