How can I limit DateTimePicker to change date, not time?

Here's the situation:

I have two DateTimePicker controls for the start and end dates in the log viewer. I want the start date to be what the user selects, but from 00:00:00. End time is the date that the user selects, but the time is 23: 59: 59.999.

(I will also write code so that the end date is equal to or greater than the start date, but I can handle this)

What is the best way to implement this?

+3
source share
2 answers

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...
        }
    }
+3
source

DatePicker DateTimePicker / , , , .

+2

Source: https://habr.com/ru/post/1761561/


All Articles