Query Needed, Past 30days of data

Discuss the database features
Post Reply
mspeck
Posts: 1
Joined: Mon Nov 01, 2021 3:49 pm

Query Needed, Past 30days of data

Post by mspeck »

Good morning, I'm having an issue writing a simple query to show all data for the past 30 days and I believe it is due to the StartDate field which has the date and the time. Could someone help me figure out what is going on with this query ?

Code: Select all

SELECT * FROM "QCSReelData" WHERE DATEDIF('day', "StartDate", CURRENT_DATE)<=30
OpenOffice 4.1 on Windows 10
User avatar
Sliderule
Volunteer
Posts: 1279
Joined: Thu Nov 29, 2007 9:46 am

Re: Query Needed, Past 30days of data

Post by Sliderule »

mspeck wrote:Good morning, I'm having an issue writing a simple query to show all data for the past 30 days and I believe it is due to the StartDate field which has the date and the time. Could someone help me figure out what is going on with this query ?

Code: Select all

SELECT * FROM "QCSReelData" WHERE DATEDIF('day', "StartDate", CURRENT_DATE)<=30
I will answer this question, assuming you are using HSQL as your database back-end, since you have NOT told us in your Original Post ( AKA OP ):
  1. The name of the function is: DATEDIFF NOT DATEDIF. Therefore correct it.
  2. In the event ( you will have to try it determine if this is applicable ) . . . you MAY . . . need to change your column from a TIMESTAMP to a DATE . . . by using a CAST . . . for example:

    Code: Select all

    CAST("StartDate" as DATE)
Bottom line:
  1. I would first try the following Query:

    Code: Select all

    SELECT * FROM "QCSReelData" WHERE DATEDIFF('day', "StartDate", CURRENT_DATE)<=30
  2. and if above returns an error, try the following Query:

    Code: Select all

    SELECT * FROM "QCSReelData" WHERE DATEDIFF('day', CAST("StartDate" as DATE), CURRENT_DATE)<=30
I hope this helps, please be sure to let me / us know.

Thanks to add [Solved] in your 1st post Subject (edit button top right) if this issue has been resolved.
Post Reply