R sqldf not being selective in date range criteria -


i trying select rows date value less value. doesn't seem working getting date values, not less value.

here's df structure:

str(sawdf) 'data.frame':   83597 obs. of  10 variables:  $ actiondate       : date, format: "2016-05-08" "2016-05-08" "2016-05-09" ... 

and here's sample data:

head(sawdf)   actiondate  2016-05-14 2016-05-15   2016-05-16  2016-05-17  2016-05-18 

and here sql:

sqldf("select distinct actiondate sawdf actiondate < '2016-05-18'") 

and here's of results:

... 6  2016-05-13 7  2016-05-14 8  2016-05-15 9  2016-05-16 10 2016-05-17 11 2016-05-18 12 2016-05-19 

as can see data beyond 2016-05-18 being selected.

i've tried several approaches getting same results.

thanks

i can't comment yet, @gregor has great solution. if bound , determined use sql though, can first convert date character (since sqlite doesn't have date type):

sawdf <- data.frame(actiondate = as.date(c("2016-05-14", "2016-05-15", "2016-05-30"))) sawdf$actiondate <- as.character(sawdf$actiondate) str(sawdf)  sqldf("select actiondate    sawdf substr(actiondate,1,4)||substr(actiondate,6,2)||substr(actiondate,9,2) < '20160520'")    actiondate 1 2016-05-14 2 2016-05-15