Solved

I need this quarter for my datetimepickers

Posted on 2014-12-16
2
102 Views
Last Modified: 2014-12-17
I am setting my datetimepickers sor this quarter and I keep getting  an error - the error is Year, Month, and Day parameters describe an un-representable DateTime. Any ideas?
 DateTime date = DateTime.Now;
                        int Quarter = (date.Month - 1) / 3 + 1;
                        DateTime first = new DateTime(date.Year, 3 * Quarter - 2, 1);
                        DateTime last = new DateTime(date.Year, 3 * Quarter + 1, 1).AddDays(-1);<- here is error
                      
                        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");

Open in new window

0
Comment
Question by:r3nder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40504234
Hi,

It does not understand 13 months

pls try

DateTime last = new DateTime(date.Year, 3 * Quarter -2, 1).AddMonths(3).AddDays(-1);

Regards
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40504640
Thanks Rgonzo!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question