Reputation: 59
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?
Upvotes: 3
Views: 3351
Reputation: 6982
Use maximumDate
property of your date picker.
let yesterdayDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())
yourPicker.maximumDate = yesterdayDate
Upvotes: 4
Reputation: 1086
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
}
Upvotes: 0