Jump to content

where clause help?

lee mcdermott

Recommended Posts



I'm trying to setup a widget to show number of calls logged last month.


I have this for calls logged in last 7 days.

h_requesttype = 'incident' AND h_datelogged >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)

What is the syntax for calls logged last month?


Also is there a list of common syntax available anywhere i.e. how to get different dates things like that?


I'm not particularly familiar with sql code so struggling a bit when trying to setup some new widgets.





Link to comment
Share on other sites

  • 2 weeks later...

Hi @lee mcdermott

Sorry for the delay. You could try the following which should bring back last months requests:

h_datelogged >=  LAST_DAY(NOW() - INTERVAL 2 MONTH) + INTERVAL 1 DAY and h_datelogged <  LAST_DAY(NOW() - INTERVAL 1 MONTH)

We don't have an official Hornbill reference to Date and Time functions as it typically standard SQL. There is a good guide here to some of the functions: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

Also, I have created a reference that I often use as a prompt when a useful statement appears:


(n.b I'm sure there may be more efficient ways tp get the same results! But these have worked for me previously)

Hope this helps


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...