r3nder
asked on
Setting DateTimePicker to last quarter
I have a datetime picker that I am trying to set to "Last Quarter" currently it shows 1/1/2015 - 3-31-2015
not last quarter 10-1-2014 - 12-31-2014
not last quarter 10-1-2014 - 12-31-2014
DateTime date = DateTime.Now;
int Quarter = (date.Month - 1) / 4 + 1;
DateTime first = new DateTime(date.Year, 3 * Quarter - 2, 1);
DateTime last = new DateTime(date.Year, 3 * Quarter - 2, 1).AddMonths(3).AddDays(-1);
dateTimePicker_ReportsStart.Text = first.ToString("MM,dd,yyy 00:00:00");
dateTimePicker_ReportsTimeStart.Text = first.ToString("MM,dd,yyy 00:00:00");
dateTimePicker_ReportsEnd.Text = last.ToString("MM,dd,yyy 23:59:59");
dateTimePicker_ReportsTimeEnd.Text = last.ToString("MM,dd,yyy 23:59:59");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Shaun
that fixes first day but not last
First is 10-1-2014 but last is 3-31-2015 and if I add the same logic to last-- I get 9-30-2014
that fixes first day but not last
First is 10-1-2014 but last is 3-31-2015 and if I add the same logic to last-- I get 9-30-2014
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Shaun
Is this what you want:
int Quarter = (date.Month - 3) / 4 + 1;
as there are 3 months in a quarter