-1
我想計算去年的未使用假期並將其顯示在網格列中。我知道我必須做一個簡單的計算如何檢查去年
,如:
VacationDays - UsedVacationDays ==從去年
但剩下的假期我該怎麼查,我只收到從去年的數據?我知道,必須有一些與DateTime.Today.AddYears(-1),至少我覺得洙..
到目前爲止我的代碼:
public double UnusedVacationDays
{
get
{
return (this.VacationDays - this.UsedVacationDays);
}
}
編輯
public double GetUsedVacation(int year)
{
double hours = 0;
IEnumerable<HtVacationDay> vacationDays = this.HtVacationDays.Where(x => x.FromDate.Year == year && x.FromDate < DateTime.Today);
foreach (HtVacationDay vacation in vacationDays)
{
TimeSpan span = vacation.ToDate - vacation.FromDate;
if (span.TotalHours > 8)
{
hours += span.TotalHours/3;
}
else
{
hours += span.TotalHours;
}
}
return hours/8;
感謝您的幫助! ^^
因此,你有兩個雙精度值(例如'12.0'和'6.5'),並且想要找到它們去年的哪一部分? –
檢查日期的'.Year'屬性? –
@SergeyBerezovskiy是的! – TamoDaleko