c# – Field format to save time

Question:

Which field should I use in SQL Server to save a duration time? E.g.: 2Days 23H 47Min 00Sec.

If you have an example with Fluent API it will help a lot.

Answer:

The correct .NET type for representing time durations is TimeSpan .

It is possible to use the Time type to store this data, according to this compatibility table .

Using .NET 6 onwards it is possible to adopt TimeOnly .

Something that people usually do is also use an INT or BIGINT to store ticks or milliseconds or even seconds , according to the precision you need.

As the question does not give details, I cannot go beyond that.

Scroll to Top