Relative Date and Time Shortcuts

Optionally, you can add or subtract relative time shortcuts to the absolute times. The following table outlines the relative time shortcuts.

Table 1. Relative Date and Time Shortcuts
Time SegmentMeaning
sSecond
mMinute
hHour
dDay
wWeek
microMicrosecond

You can use relative time shortcuts when defining time intervals. For instance, use these shortcuts when you specify a value for the IntervalMilliseconds column.

Note: You cannot use relative time shortcuts to add or subtract microseconds to or from absolute times.

Example 1: Set the Start Time to 10 Days Before Yesterday and End Time to Today

SET starttime=yesterday-10d, endtime=today
SELECT * FROM ihQuerySettings

Example 2: Retrieve the Previous 24 Hours of Messages

SELECT * FROM ihMessages WHERE timestamp>=Now-24h

Example 3: Select Data Starting at 1AM Yesterday and Ending Now

SELECT * FROM ihrawdata WHERE timestamp>=yesterday+1h AND timestamp<=now

Example 4: Retrieve Raw Data With a 1 Hour (3600000 Milliseconds) Interval Between Returned Samples

SELECT * FROM ihrawdata WHERE intervalmilliseconds=1h

Example 5: Retrieve Raw Data With a 100 Microseconds Interval Between Returned Samples

SELECT * FROM ihrawdata WHERE intervalmilliseconds=100micro and starttime>= '7/12/2011 12:03:16.100000' and endtime<=' 

Example 6: Retrieve This Week's Output to Date

SET starttime=Sun, endtime=Now, intervalmilliseconds=1d, samplingmode=rawbytime
SELECT tagname, SUM(value) FROM ihRawData WHERE tagname LIKE *00* GROUP BY tagname