search between two dates string in sql code example

Example 1: python datetime get all days between two dates

from datetime import date, timedelta

sdate = date(2008, 8, 15)   # start date
edate = date(2008, 9, 15)   # end date

delta = edate - sdate       # as timedelta

for i in range(delta.days + 1):
    day = sdate + timedelta(days=i)
    print(day)

Example 2: how to get the date diff of 2 dates in the same fieldin sql server

WITH Partitioned AS(	SELECT *, ROW_NUMBER() OVER (PARTITION BY cu_id, date ORDER BY cu_id, date) AS RowNumber	FROM @Table) SELECT 	*,	CASE 		WHEN RowNumber > 1 THEN 0		ELSE COALESCE(DATEDIFF(DAY, (SELECT MAX(date) FROM @Table WHERE date < a.date AND cu_id = a.cu_id), a.date), 0)	END AS Days_betweenFROM Partitioned a