0

I have two date pickers. Let's say fromDatePicker and untilDatePicker. I set the untilDatePicker to current date (ex: 12/06/17) and I want to set the fromDatePicker into first date of the current month (ex: 01/06/17) but I don't have any idea to set the untilDatePicker.

I have read this question but it's not helped me much.

halfer
  • 19,824
  • 17
  • 99
  • 186
MrX
  • 953
  • 2
  • 16
  • 42

1 Answers1

1

This is swift3 solution and how you set first day of current month in datePicker , if you need to get first of other month just change date variable with some day from that month

    let date = NSDate()
    let calendar = NSCalendar.current
    let components = calendar.dateComponents([.year,.month], from: date as Date)
    let startOfMonth = calendar.date(from: components)
    self.datePicker.setDate(startOfMonth!, animated: true)