Solved

I need this quarter for my datetimepickers

Posted on 2014-12-16
2
106 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 51

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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