Solved

I need this quarter for my datetimepickers

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

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
Thanks Rgonzo!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now