[Solved] How to select date of last 5 days? [closed]

[ad_1]

You can use a recursive CTE:

with dates as (
      select cast(getdate() as date) as dte
      union all
      select dateadd(day, -1, dte)
      from dates
      where datediff(day, dte, getdate()) <= 4
     )
select  *
from dates
order by dte desc;

Obviously, you can reference any other date you want instead of getdate(). Your example suggests that the current date is 2015-11-14, which was a while ago.

[ad_2]

solved How to select date of last 5 days? [closed]