- 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)));
}
// ...
}
Головоломочка для любителей поиграться с датами... :)
Lure Of Chaos 19.07.2010 16:14 # −1
da4ever 20.07.2010 04:46 # +4