Search code examples
delphidatetimepicker

How do I disable TDateTimePicker dates beyond a certain time?


How do I disable TDateTimePicker from allowing selecting dates beyond the system date & time? E.g., if my system date is 06 Nov 2012, I should not be able to select dates beyond 06 Nov 2012.

Furthermore, can we do something for selecting dates only within a particular range?


Solution

  • You could use the MaxDate property of the TDateTimePicker class to set the maximum allowed date.

    Somewhere in the form you can add

    DateTimePicker1.MaxDate := Now;
    

    Also, there is the MinDate property which prevents selection of dates older than the one specified.