Hi
I have below code and Time is system is stored as below in Database . I want Documents created in last 5 min from Current Date and Time.. If now is 17:00 than I need documents added from 16:55 till 17:00
Query is in Hana version
14:37
15:36
SQL
SELECT
T0."DocDate" "Doc. Date",
T1."Remarks" FROM OWDD T0 inner
join WDD1 T1 on T1."WddCode" = T0."WddCode"
where T1."Status" = 'W'Thanks

Sreenath KappoorRank #655 · 3.7K reputationPosted Jan 16, 2025, 1:05 AM EST
Hi Ramco,
Add this to the where condition,
T0."DocDate" >= ADD_SECONDS(CURRENT_TIMESTAMP, -300);
Tuhin PaulRank #7 · 71.9K reputationPosted Jan 18, 2025, 1:12 AM EST
To retrieve documents that were created in the last 5 minutes from the current date and time in SAP HANA, you need to filter the
DocDatebased on the current system time. In HANA, you can useCURRENT_TIMESTAMPto get the current system time.SELECT T0."DocDate" AS "Doc. Date", T1."Remarks" FROM OWDD T0 INNER JOIN WDD1 T1 ON T1."WddCode" = T0."WddCode" WHERE T1."Status" = 'W' AND T0."DocDate" >= CURRENT_TIMESTAMP - INTERVAL '5' MINUTETuhin PaulRank #7 · 71.9K reputationPosted Jan 18, 2025, 1:14 AM EST
Optimized version of the query is :
SELECT T0."DocDate" AS "Doc. Date", T1."Remarks" FROM OWDD T0 INNER JOIN WDD1 T1 ON T1."WddCode" = T0."WddCode" WHERE T1."Status" = 'W' AND T0."DocDate" >= SYSDATE - INTERVAL '5' MINUTEWhy this is more efficient: