[R] Compare date Oracle with Sys.time

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Jul 6 20:00:37 CEST 2012

Yes, this request is woefully incomplete, but it looked to me like the question was how to select the data so that a limited amount of data could be imported, rather than loading the whole table and subsetting in R.  If so, the discussion should be about constructing appropriate SQL (with or without parameters), which seems out of scope for this list (perhaps R-sig-DB?).
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

Marc Schwartz <marc_schwartz at me.com> wrote:

>On Jul 6, 2012, at 10:50 AM, cindy.dol wrote:
>> I would like to import only datas of my table where DATE>today-7days.
>> But my datas in Oracle are 'dates' and in R are 'characters'.
>> now_7<-format(Sys.time()-(7*60*60*24), "%Y-%m-%d 00:00:00")
>> How to do?
>Huh? How are you getting the data from Oracle into R?
>Typically Oracle DATE/TIMESTAMP data types come over as ?POSIXct in R,
>if using facilities such as RODBC, which means using a regular date
>based comparison. 
>  str(DF)
>where 'DF' is your data frame, to review the structure of it.
>If your data frame is called DF and your date/time column is called
>MyDATE, you can use as.Date() to coerce both to ?Date class and then do
>the subtraction with days as the unit of measurement:
>  NewDF <- subset(DF, as.Date(Sys.time()) - as.Date(MyDATE) < 7)
>If for some reason, you are importing your data via another means into
>R, then you can still use ?as.Date to coerce the column to a Date class
>and use the above incantation.
>See ?subset for additional information on that function.
>Marc Schwartz
>R-help at r-project.org mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list