Difference between 2 dates in weeks and days using swift 3 and xcode 8

You can use Calendar‘s dateComponents(_:from:to:) to find the difference between 2 dates to your desired units. Example: let dateRangeStart = Date() let dateRangeEnd = Date().addingTimeInterval(12345678) let components = Calendar.current.dateComponents([.weekOfYear, .month], from: dateRangeStart, to: dateRangeEnd) print(dateRangeStart) print(dateRangeEnd) print(“difference is \(components.month ?? 0) months and \(components.weekOfYear ?? 0) weeks”) > 2017-02-17 10:05:19 +0000 > 2017-07-10 07:26:37 +0000 … Read more

How to compare two dates in Objective-C

Cocoa has couple of methods for this: in NSDate – isEqualToDate: – earlierDate: – laterDate: – compare: When you use – (NSComparisonResult)compare:(NSDate *)anotherDate ,you get back one of these: The receiver and anotherDate are exactly equal to each other, NSOrderedSame The receiver is later in time than anotherDate, NSOrderedDescending The receiver is earlier in time … Read more

Comparing Dates in Oracle SQL

31-DEC-95 isn’t a string, nor is 20-JUN-94. They’re numbers with some extra stuff added on the end. This should be ’31-DEC-95′ or ’20-JUN-94′ – note the single quote, ‘. This will enable you to do a string comparison. However, you’re not doing a string comparison; you’re doing a date comparison. You should transform your string … Read more