Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:11:16+00:00 2026-06-06T16:11:16+00:00

So often, I want the user to select a start date and a finish

  • 0

So often, I want the user to select a start date and a finish date. But just selecting date is not enough, we also have to alter the data.

By default, the DateTimePicker.Value are like

Value 1: 2012-01-01 10:12:09
Value 2: 2012-01-02 10:12:09

When the user selects two dates, it should be obvious that he meant

Value 1: 2012-01-01 00:00:00
Value 2: 2012-01-02 23:59:59

I often forget to do the non-intuitive

DateTime start = dateTimePicker1.Value.Date;
DateTime finish = dateTimePicker2.Value.Date.AddDays(1).AddSeconds(-1);

What more effective way of dealing with this have you found?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:11:17+00:00Added an answer on June 6, 2026 at 4:11 pm

    If you use DateTimePicker objects lke this a lot, you could possible create two small custom classes: a StartDateTimePicker and an EndDateTimePicker. Each class would derive from DateTimePicker, and would simply have a boolean and an EventHandler on the OnValueChanged event. The event would be used to adjust the value after it is set, and the boolean would be used to implement the Balking Pattern. Here’s an example of the StartDateTimePicker:

    public class StartDateTimePicker : DateTimePicker
    {
        bool handling = false;
    
        // Note: 
        public StartDateTimePicker()
            : base()
        {
            // This could be simplified to a lambda expression
            this.ValueChanged += new EventHandler(StartDateTimePicker_ValueChanged);
        }
    
        void StartDateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            // If the value is being changed by this event, don't change it again
            if (handling)
            {
                return;
            }
            try
            {
                handling = true;
                // Add your DateTime adjustment logic here:
                Value = Value.Date;
            }
            finally
            {
                handling = false;
            }
        }
    }
    

    You would then simply use these in place of your normal DateTimePicker objects and you would not have to worry about making sure that the dates are appropriately adjusted anymore.

    It would cost you the time to write the EndDateTimePicker class (the above is already a fully functional StartDateTimePicker), but it would make things easier down the road as you use these in more places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often want to redirect the user or email them a link but I
I often want to trigger a certain function just once, but I need to
As an artist and musician, I often want to sit down and just let
I have a widget containing multiple child objects, which the user can select by
Often I'm creating reports in Visual Studio's Crystal Reports and want to have a
I often have a class where I want to allow a functionality to be
i often use but i have this problem. if there is a whose action
I often want to change to the directory where a particular executable is located.
I often want to send sample apps to friends & colleages that work with
I'm putting together a Swing application where I often want to replace the contents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.