Check if date falls between 2 dates

if date is between two dates excel then return value
excel if date range falls within date range
excel if date is between range then return value
check if date is between two dates python
check if date is between two dates javascript
index match between two dates
excel sumif between two dates
check if date is between two dates c#

I have this code where convert a String into a date object

let date2 = KeysData[indexPath.row]["starttime"] as? String

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

if let date = dateFormatter.dateFromString(date2!) {

I would like to know if the current date falls between the 2 days i got in the array startdate and endate

Swift 2

For a better answer see Swift ≧ 3.

You already have the code for conversion of your date string in KeysData to NSDate. Assuming you have the two dates in startdate and enddate, all you have to do is check if the current date is in between:

let startDate = ...
let endDate = ...

NSDate().isBetween(date: startDate, andDate: endDate)

extension NSDate {
    func isBetweeen(date date1: NSDate, andDate date2: NSDate) -> Bool {
        return ==

Edit: If you want to perform an inclusive range check, use this condition:

 extension NSDate {
    func isBetween(date date1: NSDate, andDate date2: NSDate) -> Bool {
        return * >= 0

Determining If a Date is between Other Dates (Microsoft Excel), Johna needs to determine if a particular date is between two other dates. For instance, she may need to determine if November 8, 2018, is  VLOOKUP Value If Date Falls between Two Dates Assuming that you have a list of data in Range A1:C4, which contain start date, end date, and Sales product, and you want to lookup a given date (2019/4/3), if this date falls between the start dates and end dates, and then return its corresponding product name.

Swift ≧ 3

Swift 3 makes this a lot easier.

let fallsBetween = (startDate ... endDate).contains(Date())

Now that NSDate is bridged to the value type Date and Date conforms to Comparable we can just form a ClosedRange<Date> and use the contains method to see if the current date is included.

Caveat: endDate must be greater or equal startDate. Otherwise the range could not be formed and the code would crash with a fatalError.

This is safe:

extension Date {
    func isBetween(_ date1: Date, and date2: Date) -> Bool {
        return (min(date1, date2) ... max(date1, date2)).contains(self)

Check if a date is between two dates – Excel, If you want to check whether the particular date is between two other dates, you can easily do it in Excel. In the following example, we have a  Type this formula into Cell B1, and press Enter key in your keyboard, and then drag the AutoFill Handle from Cell B1 to B5. If the data falls between the given two dates, and this formula return TRUE, otherwise, return FALSE.

For Swift 4.2 I used this extension based on answer above:

extension Date {
    func isBetween(_ date1: Date, and date2: Date) -> Bool {
        return (min(date1, date2) ... max(date1, date2)) ~= self

But be careful. If this extension doesn't include your start date (date1), then check the time of your dates. May be you'll need to cut the time from dates to fix it. For example, like this:

let myDateWithoutTime = Calendar.current.startOfDay(for: myDate)

Returning a value if cell date is between two dates, The cell can contain 1/18/2010 but be formatted to appear as "mmmm d, yyyy" and you can still check if it's in a range. If your "dates" are actually  Vlookup between two dates and return corresponding value with formulas. To get the relative value on which date falls between two dates, the below Lookup formula may help you. Please do as this: 1. Enter the below formula into a blank cell where you want to place the result:

extension Date
    func isBetween(startDate:Date, endDate:Date)->Bool
         return ( == .orderedAscending) && ( == .orderedDescending)

How to VLOOKUP to Return Value if Date Falls between Two dates , How do I VLOOKUP between two dates and return corresponding value with lookup formula in Excel. How to lookup a value if the date fall  If date falls between two dates then return true Hi, I need a formula in column that if a date in range A3:A32 falls between the dates entered in A1:A2, to return true otherwise leave blank.

extension Date {

    func isBetweeen(date date1: Date, andDate date2: Date) -> Bool {
        return date1.timeIntervalSince1970 < self.timeIntervalSince1970 && date2.timeIntervalSince1970 > self.timeIntervalSince1970


Lookup if date is between 2 dates, then return an associated value , Hello:) Is there a way to lookup a date, determine if it falls between 2 dates (fiscal year quarters), and then return the corresponding value? ie: Adding a New Column to calcaute the Period a date falls between and getting error - table of multiple vaules was supplied when a single value was expected. Date Period = CALCULATE (VALUES (Period[PERIOD]),FILTER (Period,Period[START_DATE]<=EARLIER(SCOMMON[Dates])&&Period[END_DATE]>=EARLIER(SCOMMON[Dates])))

Check if one date is between two dates, Date.parse supports the format mm/dd/yyyy not dd/mm/yyyy . For the latter, either use a library like moment.js or do something as shown below var dateFrom  Checking if a value falls between 2 other values is fairly common when you are working with data. In this article, we are going to learn how to check for such between conditions in excel. You will also be learning how to check if a date or text falls between 2 other dates or texts (when arranged in dictionary order) using Microsoft Excel Spreadsheet Formulas.

Return a value if date is between two dates - Dates, I would like to create an IF statement that will return a value if the date in a cell ( R6) is between two dates (B1 and B2). I can easily create an if  I have a date column on a datagrid and I want to be checking if each date on the datagrid is between two dates. Forexample, if have date 12-03-2007 and date 30-08-2008 now I want to compare if date 12-06-2008 is on

Test if day of month falls between two dates, I have a spreadsheet that projects cash flows by week. Each column represents " The week of [date]" where [date] is the Monday of a - 291339. For instance, let's assume that you have your starting date (August 1, 2018) in cell A1 and your ending date (July 31, 2019) in cell A2. You could place the date to check into cell D1 and use the following formula: =IF (AND (D1>=A1,D1<=A2),"Yes","No")

  • That's a nice "trick", but perhaps one should add that this checks for "strictly between", i.e. the start and end date are not included (which may or may not be wanted).
  • @NikolaiRuhe hey, thanks for your answer, but did you solve Martin R note? I faced the same issue too, the start date and end date are the same date, so when I follow your answer, this rang didn't return true
  • It's perhaps not the safest thing to depend on the underlying value of NSComparisonResult in this way. It's an Int value because the enum is used by Objective-C which only allows enums of integer type. multiplying the raw values together assumes the values of the underyling integers, which I don't think is guaranteed.
  • @Abizern I agree that using the raw values in this way is a bit obfuscated. On the other hand: How are the values not guaranteed to be exactly -1, 0 or +1? The documentation and headers clearly define the integer values. A lot of code would break if the values of NSComparisonResult would change at some point.
  • @Abizern I agree that the second code example with the inclusive check is too obfuscated.
  • Might be worth editing your previously accepted answer with this. This is great!
  • @XcodeNOOB: Works for me. Swift's ClosedRange and contains semantics imply that both start and end dates are inclusive: (startDate...endDate).contains(startDate) == true and (startDate...endDate).contains(endDate) == true.
  • Just a warning, if startDate is ever later than endDate the app will crash. Unless you're 100% sure that will never be the case, you may want to add guard startDate < endDate else {...}
  • Sorry @leviathan but I found your edit contained too much code and was distracting from the simplicity of Swift's solution. I added a note that explains the problem my way.
  • date1...date2 ~= self?