Home > Mobile >  How can i get dates Saturday to Friday using SQL getdate()
How can i get dates Saturday to Friday using SQL getdate()

Time:01-16

How can I get use gatedate() to always pick up the last Saturday to current Friday.
When I try to use the code I getting a static Saturday date

I have tried this way

Select 
cast dateadd(y,datediff(y,0,getdate()),-1 ) as date) as Satuday,
cast(dateadd(d,-3,dateadd(week,datediff( week,0,getdate()),0)) as Friday

example
Saturday date = 31/12/2023
Friday date = 6/01/2022

CodePudding user response:

Try the following code, you can adjust the code...

   SELECT DATEADD(DD, 12, DATEADD(ww, DATEDIFF(ww, 0, DATEADD(dd, -6, CURRENT_TIMESTAMP)) -1, 0)) -- Saturday
    SELECT DATEADD(DD, 18, DATEADD(ww, DATEDIFF(ww, 0, DATEADD(dd, -6, CURRENT_TIMESTAMP)) -1, 0)) -- Friday
  • Related