[Solved] How to compare array of dates with greater than current date

i Resolved my issue by using stack overflow suggestions. and i am posting my answer it may helpful for others. extension Date { var startOfWeek: Date? { let gregorian = Calendar(identifier: .gregorian) guard let sunday = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)) else { return nil } return gregorian.date(byAdding: .day, value: 1, to: sunday) } var … Read more

[Solved] How do I convert a parameterised enum/ enum with associated values from Swift to Objective-C? [closed]

Let me explain your code for you: NSString *isoFormat = ISO8601DateFormatType; (assigns string ISO8601 to isoFormat) NSString *dateFormat = (isoFormat != nil) ? isoFormat : ISO8601DateFormatType; (isoFormat is never nil so the condition is always true. If it were false, we would again assign string ISO8601). NSDateFormatter *formatter = … (we get some formatter, it … Read more

[Solved] How to compare two time from NSDate. Returning nil for nsdate when doing comparision. #debug my code

There was a typo:[dateFormatter setDateFormat:@”HH:mm:ss”]; should be:[formatter setDateFormat:@”HH:mm:ss”]; To compare two dates use: NSDate *date1 = [NSDate date]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@”HH:mm:ss”]; NSDate *date2 = [formatter dateFromString:@”05:00:00″]; NSComparisonResult result = [date1 compare:date2]; if(result == NSOrderedDescending) { NSLog(@”date1 is later than date2″); } If you only want to compare the hours: NSCalendar … Read more

[Solved] Converting Date to proper format when the Value obtained from the Db is in format 2012-07-13 00:00:00.0 [duplicate]

Use this one NSString *[email protected]”2012-07-13 00:00:00.0″; NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@”yyyy-MM-dd HH:mm:ss.S”]; NSDate *date = [df dateFromString: dateStr]; [df setDateFormat:@”MM/dd/yyyy”]; NSString *convertedString = [df stringFromDate:date]; NSLog(@”Your String : %@”,convertedString); Output: Your String : 07/13/2012 6 solved Converting Date to proper format when the Value obtained from the Db is in format 2012-07-13 … Read more

[Solved] how to I convert a string with format “YYYY/MM/DD” into NSDate type? [duplicate]

You can convert it to an NSDate using the NSDateFormatter. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@”yyyy/MM/dd”]; NSdate *date = [dateFormatter dateFromString:@”2012/03/17″]; Be aware that allocating an NSDateFormatter is a pretty heavy task so if you are parsing a lot of dates then allocate it once and keep it around 🙂 solved how to … Read more