- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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)));
}
// ...
}
Головоломочка для любителей поиграться с датами... :)