Get the day name (example: Monday, Tuesday, ..... ) from a selected date from datepicker
let day = dateFormatter.string(from: date)
Get the day name (example: Monday, Tuesday, ..... ) from a selected date from datepicker
let day = dateFormatter.string(from: date)
To get the weekday do the following:
let dateFormatter = DateFormatter()
var weekday: String = ""
dateFormatter.dateFormat = "cccc"
weekday = dateFormatter.string(from: date)
Read more about the different formats here: http://userguide.icu-project.org/formatparse/datetime
Add this extension in below any file in the project. (better make an extension file and add there.)
extension Date {
func dayNameOfWeek() -> String? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
return dateFormatter.string(from: self)
}
}
Usage:
let dayName = date.dayNameOfWeek()