RZRKAL
RZRKAL

Reputation: 417

How to know if a date is in an interval using lubridate?

If I have a lubridate interval: "2010-02-20" %--% "2012-03-15" How may I know if a date, say "2011-01-12", is in that range?

I am using lubridate and the tidyverse packages.

Upvotes: 1

Views: 437

Answers (2)

MLEN
MLEN

Reputation: 2561

library(data.table) 
ymd("2011-01-12") %between% c("2010-02-20", "2012-03-15")

library(dplyr)
between(ymd("2011-01-12"), "2010-02-20", "2012-03-15")

Upvotes: 0

Adam Quek
Adam Quek

Reputation: 7153

ymd("2011-01-12") %within% ("2010-02-20" %--% "2012-03-15")

# [1] TRUE

Upvotes: 4

Related Questions