views:

45

answers:

2

Here's the situation:

I have two DateTimePicker controls for the start date and end date in a log viewer. I want the start date to be whatever the user picks, but with a time of 00:00:00. The end time to be the date the user picks, but a time of 23:59:59.999.

(I'll also be writing code the ensure the end date is equal to or greater than the start date, but I can handle that)

What is the best way to implement this?

+2  A: 

Use a DatePicker instead of a DateTimePicker and/or subscribe to the change events and force the time you want every time the value is changed.

Jay
This is Winforms, not WPF.
Hans Passant
@Hans The original question was not tagged as such.
Jay
A: 

Just ignore the time part of the date you get from DTP with DateTime.Date. Like this:

    private void btnOK_Click(object sender, EventArgs e) {
        var start = dtpStart.Value.Date;
        var end = dtpEnd.Value.Date.AddDays(1).AddMilliseconds(-1);
        if (end > start) {
            // etc...
        }
    }
Hans Passant
That's the ticket! Thanks kindly for the assistance!
Falconeer