Get Weekday from Date – Swift 3

Presumably you have a Date already?

let weekday = Calendar.current.component(.weekday, from: myDate)

Maybe you want the name of the weekday?

let f = DateFormatter()

f.weekdaySymbols[Calendar.current.component(.weekday, from: Date()) - 1]

The -1 is added at the end because Calendar.current.component(.weekday, from: Date()) returns values from 1-7 but weekdaySymbols expects array indices.

Investigate the NSCalendar/DateComponents api or edit your question to be more specific if you need help with the DateComponents api.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)