S
S
SLJ2020-03-13 09:16:49
SQL
SLJ, 2020-03-13 09:16:49

How to subtract 12 hours from a date in sql?

Good day. There is a request to the current sales database. DBMS Firebird 2.1. The request is made through isql.

SELECT
    C.CODE AS "Табельный",
    C.NAME AS "Ф.И.О.",
    T.TRANZDATE AS "Дата",
    max(T.TRANZTIME) AS "Время",
    T.INFOSTR AS "Карта",
    sum(T.SUMM) AS "Сумма"
FROM
    DOCUMENT D
        LEFT JOIN TRANZT T ON D.ID = T.DOCUMENTID
        JOIN CLIENT C ON T.INFO2 = C.CODE  -- òàá íîìåð
WHERE
      T.TRANZDATE = cast('now' as date) and
      T.TRANZTIME >='20:00:00' AND T.TRANZTIME <='08:00:00' AND
      D.STATE = 1 AND 
      D.ISFISCAL = 1 AND 
      T.TRANZTYPE = '36' and 
      T.INFO = '8' 
GROUP BY
    C.CODE,
    C.NAME,
    T.TRANZDATE,
    T.INFOSTR

The request is sent to the database 2 times a day at 8 am and 8 pm. It is necessary to calculate the intervals from 08:00:00 to 20:00:00 in the current date, do this:
T.TRANZDATE = cast('now' as date) and
T.TRANZTIME >='08:00:00' AND T.TRANZTIME <='20:00:00' AND

how to execute a query in the interval 03/12/2020 20:00:00 to 03/13/2020 08:00:00?
T.TRANZDATE = cast('now' as date) and
T.TRANZTIME >='20:00:00' AND T.TRANZTIME <='08:00:00' AND

those. subtract 12 hours from the current date.
tried something like that
T.TRANZDATE = dateadd (hour, -12, current_timestamp)  and

But it doesn't give the desired result. The request is executed daily, automatically.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-03-13
@sergiks

Example from documentation :
dateadd (-12 hour to current_time)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question