Closed xs6615 closed 7 years ago
Sure! Post your code here and I can help you!
I am using the basic code in the sample. The format I need is below. THANK YOU!
@IBAction func datePickerTapped(sender: AnyObject) {
let currentDate = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
var dateComponents = DateComponents()
dateComponents.month = -12
let threeMonthAgo = Calendar.current.date(byAdding: dateComponents, to: currentDate)
DatePickerDialog().show("Select a date", doneButtonTitle: "Done", cancelButtonTitle: "Cancel", minimumDate: threeMonthAgo, maximumDate: currentDate, datePickerMode: .date) { (date) in
if let dt = date {
self.diveDateTextfield.text = "\(dt)"
}
}
}
@IBAction func datePickerTapped(sender: AnyObject) {
let currentDate = Date()
var dateComponents = DateComponents()
dateComponents.month = -12
let threeMonthAgo = Calendar.current.date(byAdding: dateComponents, to: currentDate)
DatePickerDialog().show("Select a date", doneButtonTitle: "Done", cancelButtonTitle: "Cancel", minimumDate: threeMonthAgo, maximumDate: currentDate, datePickerMode: .date) { (date) in
if let dt = date {
let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
self.diveDateTextfield.text = "\(formatter.stringFromDate(date))"
}
}
}
I got the code from #30
Closing this.... Feel free to reopen if it doesn't work
Works like a charm. I only had to make some slight modifications. I am posting only in case someone else needs it. THANK YOU!!!.
@IBAction func datePickerTapped(sender: AnyObject) {
let currentDate = Date()
var dateComponents = DateComponents()
dateComponents.month = -12
let threeMonthAgo = Calendar.current.date(byAdding: dateComponents, to: currentDate)
DatePickerDialog().show("Select a date", doneButtonTitle: "Done", cancelButtonTitle: "Cancel", minimumDate: threeMonthAgo, maximumDate: currentDate, datePickerMode: .date) { (date) in
if date != nil {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
self.diveDateTextfield.text = "\(formatter.string(from: date!))"
}
}
}
I have tried many ways, but cannot get the dateFormatter to work. Can someone show me how to set this up?