• SwastikMS (3/12/2014)


    But in my case, there was a difference of hours.

    I have added UTC time difference. Now the difference is coming in minutes.

    What should I do?

    First post the code you are using and some examples of the values that are have a difference. Otherwise no one will be able to help.

    There can be some inaccuracies with the method Jeff posted, but I found the differences were sub second. These differences did not matter for our purposes as it was just for diagnostics and debugging. If you use datetime2 and a loop added to the date and subtracting from the tick amount until you get to zero ticks left, the accuracies seem to go away, but that requires SQL Server 2008, which at the time was not an option (and kind of still isn't for certain of our customers). The other option is CLR which will not have any inaccuracies.

    Jedak