I am trying to create UIDatePicker
in my project which maximum date should be that of yesterday instead of current date. Is there a way to set selected date as yesterday instead of selecting current date?
Asked
Active
Viewed 3,181 times
3

Devil Decoder
- 966
- 1
- 10
- 26

kanwaljeet singh
- 59
- 1
- 5
-
2Possible duplicate of [Minimum and maximum date in UIDatePicker](https://stackoverflow.com/questions/10494174/minimum-and-maximum-date-in-uidatepicker) – amrdruid Jul 03 '18 at 10:00
-
1Is there any reason you didn't read the documentation for `UIDatePicker`? – Ashley Mills Jul 03 '18 at 10:16
2 Answers
4
Use maximumDate
property of your date picker.
let yesterdayDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())
yourPicker.maximumDate = yesterdayDate

mag_zbc
- 6,801
- 14
- 40
- 62
0
you can use below code to achieve this
let calender = Calendar.current
let date = Date()
let finalDate = calender.date(byAdding: Calendar.Component.day, value: -1, to: date)
if let FinalDate = finalDate{
yourPicker.maximumDate = FinalDate
}

Devil Decoder
- 966
- 1
- 10
- 26