简体   繁体   中英

Difference between two dates #

I have to calculate number of days difference between today and SubmittedDate, but if I the SubmittedDate = today my Result = 0,430090... Instead of 1

here is my code:

 DaysDiff = (today.Subtract(DataUtilities.GetSafeDateTime(financialStatement[SharePoint_Assessment_Fields.SUBMITTEDDATE_FIELD]))).TotalDays,

could you please help me ?

The TotalDays property is a double. It also takes the hours and minutes in account, so that might cause the subtraction of two days get fractions too.

If you want to round that, you could use Math.Round , Math.Ceiling or Math.Floor depending on your needs. Taking your expected outcome, I guess you need to use Ceiling :

double ceiledDays = Math.Ceiling(ts.TotalDays);

Or you could get the Date part of the two dates and calculate with that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM