Search code examples
sqladvantage-database-server

Subtract 30 days from current date in where clause


In my where clause i want to get only the records that have today's date and the last 30 days records. so i would want 3-29-19 through 4-29-19 records but i need this a rolling date so tomorrow it would be 3-30 through 4-30-19 Basically pulling up the last 30 days worth of records.

curdate() gets me the current date in advantage sql. im thinking maybe a between clause or something.

dateadd(dd,-30,curdate()),


Solution

  • ADS allows you to do straight math on dates (if you've got an actual date column in the table), so you can use

    WHERE datecol between curdate() - 30 and curdate()