I would like to record the date that an entity in my application was last modified.
The problem is, I wonder which approach I should take:
- Store the UTC date (e.g. using
GETUTCDATE()
orSystem.DateTime.UtcNow
) - Store the date in the current time zone (e.g. using
GETDATE()
orSystem.DateTime.Now
) - Store the date with timezone offset (e.g. using
SYSDATETIMEOFFSET()
orSystem.DateTimeOffset.Now
) - A combination of any of the above
Taking into account the following are given:
- The application is used in exactly one timezone. This will never change. It is unknown whether SQL server instances are hosted in a cloud, but the time zones should be configured correctly.
- I don't care about sub-second precision for this - even seconds precision is not really important.
- To avoid confusion, the value must preferrably appear correct for the current time zone, when queried "as-is", without using any conversion functions (in case the table is queried directly).
- I prefer to have one column only. If it is best practice to name it something like
ModificationDateUtc
, that's fine but please let me know.
Answers that do not exactly meet these specifications but touch on the theoretical side of things (when to choose what) are certainly more than welcome!