Calculate age from birth date using NSDateComponents in Swift

You get an error message because 0 is not a valid value for NSCalendarOptions. For “no options”, use NSCalendarOptions(0) or simply nil: let ageComponents = calendar.components(.CalendarUnitYear, fromDate: birthday, toDate: now, options: nil) let age = ageComponents.year (Specifying nil is possible because NSCalendarOptions conforms to the RawOptionSetType protocol which in turn inherits from NilLiteralConvertible.) Update for … Read more

Swift 3.0 : Convert server UTC time to local time and vice-versa

I don’t know what’s wrong with your code.But looks too much unnecessary things are there like you’re setting calendar, fetching some elements from string. Here is my small version of UTCToLocal and localToUTC function. But for that you need to pass string in specific format. Cause I’ve forcly unwrapped date objects. But you can use … Read more

NSDate beginning of day and end of day

Start Of Day / End Of Day — Swift 5.7 extension Date { var startOfDay: Date { return Calendar.current.startOfDay(for: self) } var endOfDay: Date { var components = DateComponents() components.day = 1 components.second = -1 return Calendar.current.date(byAdding: components, to: startOfDay)! } var startOfWeek: Date { Calendar.current.dateComponents([.calendar, .yearForWeekOfYear, .weekOfYear], from: self).date! } var endOfWeek: Date { var … Read more

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