Search code examples
informix

How to get last 90 days data from today


I am trying to get last 90 days data from today — is there any function in Informix to do that?

Like in other SQL:

Select * from table1 where DATEADD(d,-90,getdate())

Solution

  • SELECT *
      FROM Table1
     WHERE d >= TODAY - 90
    

    I'm assuming the column d in table Table1 is of type DATE or DATETIME YEAR TO DAY (or more precise but including YEAR).

    Choose your poison on > vs >=.

    Informix does not have a DATEADD function, or a GETDATE() function. The built-in zero-argument (no parentheses) function TODAY yields today's date as a DATE value; the function CURRENT YEAR TO DAY yields it as DATETIME YEAR TO DAY. You can simply use + and - to add or subtract an integer number of days to a DATE value (or subtract two DATE values to get the integer number of days between them). You typically end up using expressions such as CURRENT YEAR TO DAY - 90 UNITS DAY if you have to work with DATETIME instead of DATE values.