Search code examples
iosswiftswiftuidatepickerswiftui-list

DatePicker ClosedRange in SwiftUI


How do I set DatePicker in SwiftUI in such a way that the user cannot select a date and time from the past? They should be able to select dates and times from now and in the future.

Thanks in advance.


Solution

  • Set range to DatePicker like this:

    DatePicker("Please enter a date", selection: $wakeUp, in: Date.now...)