0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
public static byte[] GetMonthlyFinancialReport(
//...
DateTime dateInterested)
{
// ...
DateTime monthAgoDate = dateInterested;
int dayInterested = dateInterested.Day;
int daysInMonthInterested = DateTime.DaysInMonth(dateInterested.Year, dateInterested.Month);
int daysInPreviousMonth = DateTime.DaysInMonth(dateInterested.Year, (dateInterested.Month == 1) ? 12 : (dateInterested.Month - 1));
if (dayInterested == daysInMonthInterested)
{
monthAgoDate = monthAgoDate.AddDays(-1 * monthAgoDate.Day);
}
else
{
monthAgoDate = monthAgoDate.AddDays(-1 * Math.Max(daysInPreviousMonth, Math.Min(daysInMonthInterested, dayInterested)));
}
// ...
}
Головоломочка для любителей поиграться с датами... :)
Запостил:
svkandroid ,
19.07.2010 (Updated 24.03.2018 )
Комментарии (2) RSS