# Date within range?

Given a MM/DD date (12/24) and a start/end date range (11/01 - 06/24), figure out if the date is within the listed date span.

Date ranges can be sequential (05/01 - 11/01) or wrap around to the next year (11/01 - 05/01).

Examples:

• 12/24 is in 11/01 - 06/24 = True
• 06/24 is in 11/01 - 06/24 = True
• 06/24 is in 06/24 - 06/24 = True
• 06/24 is in 11/01 - 06/23 = False
• 07/24 is in 11/01 - 06/24 = False
• 07/24 is in 05/01 - 11/01 = True
• 07/24 is in 07/23 - 07/20 = True

Years do not mater. The date and/or date range is assumed to apply for any year past or future.

The end date will always be after the start date. If the end date is numerically less than the start date, we assume we are wrapping around to the next year.

The three input variables can be via any method (args, HTTP, stdin, etc..) and in any format (string, JSON, array, etc..)

Response can be boolean or any form of a yes/no/correct/etc.. string. Shortest code wins.

You cannot simply pass args to a built-in function.

• Can we take the result as an array of strings instead? I.e ['MM', 'DD']? Sep 11, 2017 at 17:38
• Test case suggestion: 11/01 - 06/24 includes 06/24? Sep 11, 2017 at 17:39
• @Mr.Xcoder are you picturing something like ['06', '24'] if right else [] or what do you mean? Sep 11, 2017 at 17:42
• For your second test case, suppose we're talking this year 2017 and next year 2018. How are we supposed to determine that 06/24 means 2018 and thus should be True rather than 2017 and thus False because it's before 11/01? Sep 11, 2017 at 17:57
• "date > start & date < end" - Then some of your test cases are wrong. I think what you mean is start<=date<=end. Sep 12, 2017 at 8:29

# Python, 31 bytes

lambda a,d,e:(e<d)>=(a<d)+(e<a)


Try it online!

Takes inputs as MM/DD in order target, start, end.

## JavaScript (ES6), 26 20 bytes

(a,b,c)=>b>c^b>a^a>c


Output is 0 if a lies within the range b...c, 1 if not. Edit: Saved 6 bytes thanks to @nwellnhof.

• What about (a,b,c)=>b>c^b>a^a>c? Sep 11, 2017 at 23:09
• @nwellnhof I can't believe I missed that - my very first attempt was b>a^a>c, but I then overlooked the simple fix...
– Neil
Sep 11, 2017 at 23:42
• You should update the byte count. Sep 11, 2017 at 23:59
• @nwellnhof Sorry, I was still reeling from the shock!
– Neil
Sep 12, 2017 at 0:00

(a%d)e=((e<a)/=(a<d))==(e<d)


Try it online!

Thanks to Leo for the trick of xor'ing the Booleans with /=.

(a%d)e=show[e>=d,d>a,a>e]!!16>'a'


Try it online!

• Your show trick is cool, but you can XOR the three elements in a more direct way with foldl1: tio.run/…
– Leo
Sep 12, 2017 at 1:01
• @Leo Nice idea, it's even shorter expanded out.
– xnor
Sep 12, 2017 at 1:09

# JavaScript (ES6), 31 bytes

Takes input as 3 strings in MM/DD format: date, range_from, range_to. Returns a boolean.

(a,b,c)=>!(b<c?a<b|a>c:a<b&a>c)


### Test cases

let f =

(a,b,c)=>!(b<c?a<b|a>c:a<b&a>c)

console.log(f('12/24','11/01','06/24')) // True
console.log(f('06/24','11/01','06/24')) // True
console.log(f('06/24','06/24','06/24')) // True
console.log(f('06/24','11/01','06/23')) // False
console.log(f('07/24','11/01','06/24')) // False
console.log(f('07/24','05/01','11/01')) // True
console.log(f('07/24','07/23','07/20')) // True

• Thanks to MM/DD format you can just use string sorting. Good idea. Sep 11, 2017 at 18:08

(b#e)d=(last$and:[or|b>e])[d>=b,d<=e]  Try it online! Saved 1 byte thanks to Laikoni • You can use infix notation to save a byte: (d#b)e=. Sep 11, 2017 at 21:16 # Perl 6, 3331 29 bytes {.>.??![>]$_!![<=] $_}  Try it online! Takes a list containing start, date, and end. -2 bytes thanks to Ramillies. • And here, you can save 2 bytes by taking 1 list argument instead. Then @_ can be written as . and [(whatever)] @_ as [(whatever)]$_. You just will need to call it like $f(($s,$d,$e)). Sep 11, 2017 at 21:33
59 bytes of code + 1 -a
$F=~s/./2/if$Fle$F;say($Fle$F&&$Fge\$F)

Input: start_date end_date target_date