0

Can anyone help me for separating datePicker values like day, month and year?

I want to sepearate them for calculation. I can not do that, I looked older questions but not convert them to my problem.

@objc func whenDoneButtonPressed(){

    let dateFormatter = DateFormatter()
    dateFormatter.dateStyle = .long
    dateFormatter.timeStyle = .none
    sulustarihiTextField.text = dateFormatter.string(from: datePicker.date)

    print((sulustarihiTextField.text!))

    self.view.endEditing(true)

}
Kerberos
  • 4,036
  • 3
  • 36
  • 55
dkorkmaz
  • 3
  • 1
  • 1
    Possible duplicate of [How to get time (hour, minute, second) in Swift 3 using NSDate?](https://stackoverflow.com/questions/38248941/how-to-get-time-hour-minute-second-in-swift-3-using-nsdate) (just change the calendar unit to .year, .month & .day) – Larme Jul 31 '18 at 15:11

1 Answers1

0
try this

func dateChanged(_ sender: UIDatePicker) {
    let components = Calendar.current.dateComponents([.year, .month, .day], from: sender.date)
    if let day = components.day, let month = components.month, let year = components.year {
        print("\(day) \(month) \(year)")
    }
}
Keyur Faldu
  • 195
  • 9