Skip to Content

Calculate difference in days between two dates in SAPB1

Hi

Using the following query

SELECT T2."DistNumber", T2."ItemCode", T2."itemName", T2."InDate",T2."U_Coil_Qty", T0."Warehouse", CURDATE() FROM OINM T0 INNER JOIN OITM T1 ON T0."ItemCode" = T1."ItemCode" INNER JOIN OBTN T2 ON T1."ItemCode" = T2."ItemCode" WHERE T0."Warehouse" ='[%1]' AND T2."U_Coil_Qty" > 0.000 GROUP BY T2."DistNumber", T2."ItemCode", T2."itemName", T2."InDate",T2."U_Coil_Qty", T0."Warehouse"

I need to show the difference in days between the T2."InDate" and CURDATE() please.

query-sapb1.png (48.9 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Nov 11, 2019 at 03:51 AM

    correct query,please try

    SELECT T2."DistNumber", T2."ItemCode", T2."itemName", T2."InDate", T2."U_Coil_Qty", T0."Warehouse", CURDATE() ,
    DAYS_BETWEEN (T2."InDate",CURRENT_DATE) AS "Days"
    FROM OINM T0
    INNER JOIN OITM T1 ON T0."ItemCode" = T1."ItemCode"
    INNER JOIN OBTN T2 ON T1."ItemCode" = T2."ItemCode"
    WHERE T0."Warehouse" = '[%1]' AND T2."U_Coil_Qty" > '0.000'
    GROUP BY T2."DistNumber",
    T2."ItemCode", T2."itemName",
    T2."InDate", T2."U_Coil_Qty", T0."Warehouse"

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 11, 2019 at 01:09 AM

    Just use the days_between() function. Example:

    select days_between('20190101',curdate()) from dummy 
    
    Add a comment
    10|10000 characters needed characters exceeded