WHERE-condition string in MS Jet SQL syntax filtering for a specific time interval
Usage
hsSqlExTimeCond(
tsField,
dateFirst = NULL,
dateLast = NULL,
inclLast = TRUE,
sqlDialect = getCurrentSqlDialect(),
dbg = FALSE
)
Arguments
- tsField
name of timestamp field
- dateFirst
Date object representing the first date of the time interval to be selected.
- dateLast
Date object representing the last date of the time interval to be selected.
- inclLast
if
TRUE
, dateLast will be included in result data set, else excluded.- sqlDialect
one of
c("mysql", "msaccess")
- dbg
if
TRUE
, debug messages are shown
Examples
if (FALSE) {
## Condition string to filter field "datetime" for timestamps
## between 21 and 22 of July 2010
from <- as.Date("2011-08-23")
to <- as.Date("2011-08-24")
cond <- hsSqlExTimeCond("Zeitst", from, to)
cond
## Output:
# TRUE AND Zeitst >= #08/23/2011 00:00:00#
# AND Zeitst <= #08/24/2011 00:00:00#
## The condition string may now be used in an SQL query
## to select data from within the time interval.
sql <- sprintf("SELECT * FROM tbl_Hyd WHERE %s", cond)
if (.Platform$OS.type == "windows") {
res <- hsSqlQuery(xmdb(), sql)
head(res)
}
## Output:
# Zeitst Q v H T_Kanal
# 1 2011-08-23 00:00:00 0 0 1.260 19.5
# 2 2011-08-23 00:01:00 0 0 1.259 19.5
# 3 2011-08-23 00:02:00 0 0 1.259 19.5
# 4 2011-08-23 00:03:00 0 0 1.259 19.5
# 5 2011-08-23 00:04:00 0 0 1.260 19.5
# 6 2011-08-23 00:05:00 0 0 1.260 19.5
}