Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 2.0, validation on DatePicker maximum Date

Suppose today's date is 16 May 2016, I want to restrict the user to display date up-to 16 jun 2016.

like image 329
Nisha Nair Avatar asked May 16 '16 05:05

Nisha Nair


Video Answer


1 Answers

Edit

Swift 3

    let datePicker = UIDatePicker()
    datePicker.maximumDate = Date()

swift 2

    let datePicker = UIDatePicker()
    datePicker.maximumDate = NSDate()

Restrict user to particular time interval

Try This: It will restrict user to select date greater than one month from current date.

let datePicker = UIDatePicker()
let secondsInMonth: NSTimeInterval = 30 * 24 * 60 * 60
datePicker.maximumDate = NSDate(timeInterval: secondsInMonth, sinceDate: NSDate())
like image 110
AkBombe Avatar answered Oct 20 '22 22:10

AkBombe