How do I ask SQL timestamp conditions?

where t_stamp between x and y

how do I properly ask SQL date questions related to t_stamp?

Like if I wanted the count during the last 5 minutes
or if I wanted the count during the month of october

You didn't mention what flavour of SQL, so speaking pseudo;

datepart(now, -5, minutes)

or if I wanted the count during the month of october

DATEPART(mm, t_stamp) = 10

or your first line is perfectly valid, just longer;

where t_stamp between '2021-10-01' and 2021-10-31'

w3 schools etc is pretty good for this

Thanks, I am on the w3 page for date

however, I don’t see where it says like now

so I copied your example, switched the October to November, got an error of out of range

so how do you handle a now() scenario? Can you use now(30000)?

really odd, with 2021-11-31 I get an error

with 2021-12-01 I don’t get an error

edit: oh no
oops

well all dates are going to be 1st to 1st now lol

MS SQL Server?
MySql/Maria?
PostGres?
etc?

I think it is just regular sql, I am using sql bridge

Try this and if it works it’s MS SQL

WHERE tstamp > DATEADD(minute, -5,  GETUTCDATE())
(t_stamp between '2021-10-01' and '2021-11-01' or t_stamp > DATEADD(minute, -500,  GETUTCDATE()));

both work, thanks very much

how often does the query get called if I bind it to a label on a perspective page though?

can I have it update every 30 seconds?

If you are using a query binding there is a polling option that you could set to 30 seconds.

If you are running the query from a script, then maybe you could create a custom property on your label, put the query binding on the custom property, then access the data from the custom property in your script.

1 Like

Thanks
I will look for the setting in the binding I am using