Get the number of weeks and days between two dates

MarkSnodgrass Portland, Oregon 🟤

I am needing to find the number of weeks and then the number of leftover days between two dates. I am open to doing this in our on-premise MS SQL, or in Magic ETL or in Redshift or MySQL, whichever is easiest. 

If I have dates of 8/1/2020 and 8/9/2020, for example, my expected result would be 1 week and 1 day. 

When I am trying MSSQL and using DATEDIFF(week, startdate,enddate) it gives me a result of 2 weeks. Not what I am wanting. 

I will need the end result to be two values: number of weeks, number of days (remaining days after the number of weeks, if there are any)

Any suggestions?

Best Answer

  • GrantSmith
    GrantSmith Indiana 🔴
    Accepted Answer



    Alternatively you can utilize DATEDIFF but by default it includes the current date as a whole day so depending on how your business rules are you may want to -1 day from your date difference to not calculate today.



    DATEDIFF(`EndDate`, `StartDate`) / 7



    MOD(DATEDIFF(`EndDate`, `StartDate`), 7)