I want to have the difference of two DateTimeOffset object in days( for example check if the difference is less than 40 days).
I know it can be done by change it to FileTime, but wondering if there is any better way of doing it.
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.
The easiest way would be to subtract the offsets from eachother. It returns a
TimeSpanyou can compare to.I tend to prefer the ability to add it to another method passing in a TimeSpan, so then you’re not limited to days or minutes, but just a span of time. Something like:
For fun, if you love fluent style code (I’m not a huge fan outside of it outside of testing and configuration)
Would allow something like:
Which reads something like “If the time from start date to now is shorter than 40 days”.