SQL get difference of row data in another row
fiddle

WITH cte (day_of_month, stock) -- add pseudo-records
AS 
( SELECT day_of_month, stock FROM test
  UNION ALL
  SELECT 1,0
  UNION ALL 
  SELECT 31,1 -- June have 30 days
),
cte2 (leadday, day_of_month, stock) -- calculate lead 
AS
( SELECT LEAD(day_of_month) OVER (ORDER BY day_of_month, stock), day_of_month, stock
  FROM cte
)
SELECT SUM(leadday - day_of_month) -- obtain data we need
FROM cte2
WHERE stock = 0;


To make sure the result is correct both when there exist the record for the first day of month and when the last record have stock = 0 uncomment appropriate values for test table data.