How to do date arithmetic to return a date as in "select ... from ... where date_field >= [today's date] - 5"

Posted on 2005-04-19
Last Modified: 2013-12-09
I need to do a query against a Firebird database and haven't seen my exact example.  I want to, in a query, do, "select ... from... where date_field >= [today's date] - 5".    I saw "current_date" in another posting, but I had thought I had to use, "get_date()"  to retrieve the system date?  Appreciate any help.  Susan
Question by:beechers
    LVL 19

    Expert Comment

    are you working in dialect 1 or 3
    LVL 10

    Expert Comment

    SELECT *
          FROM orders
          WHERE  date_field >= ’TODAY’ - 5
    LVL 19

    Expert Comment

    kacor's solution will work in dialect 1, dialect 3 will require

    select * from employee where finishdate < current_timestamp - 5
    LVL 19

    Accepted Solution

    select * from orders where recdate >= current_date - 5

    is perfectly valid and returns the current date on the server.

    You can also use current_time and current_timestamp

    Author Comment

    Thanks to all for your help!

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now