date-comparison
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
Comparing dates in MySQL ignoring time portion of a DateTime field
You could use the DATE function: SELECT col1, col2, …, coln FROM order_table WHERE date(order_date) = ‘2012-05-03’ But this is more efficient, if your table is large and you have an index on order date: SELECT col1, col2, …, coln FROM order_table WHERE order_date >= ‘2012-05-03’ AND order_date < ‘2012-05-04’
Getting date list in a range in PostgreSQL
select CURRENT_DATE + i from generate_series(date ‘2012-06-29’- CURRENT_DATE, date ‘2012-07-03’ – CURRENT_DATE ) i or even shorter: select i::date from generate_series(‘2012-06-29’, ‘2012-07-03’, ‘1 day’::interval) i
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