Solved

I need this quarter for my datetimepickers

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 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