What is a good data-type for saving hours in .net?
Is it better to use the decimal type or is the double data-type more appropriate. With hours I mean values such as:
- 2 for two hours
- 1.5 for 90 minutes
- 8.25 for 8 hours and 15 minutes.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A good way to represent a number of hours is to use a TimeSpan:
Given the choice between
decimalordoubleI’d probably go fordoubleas there is typically no expectation that the amount of time is represented exactly. If you need an exact decimal representation of your fractional number of hours (which seems unlikely) then usedecimal.You could also consider storing it as an integer in for example seconds, milliseconds or ticks.