Hello everyone. No one will tell you how to take a time stamp for the beginning of the current week? (T-sql)

    2 answers 2


      The easiest and most understandable way is this:

      DECLARE @dt char(8); SET @dt = convert(char(8),getdate(),112) SELECT DATEADD(DAY, 1-DATEPART(WEEKDAY, @dt ), @dt ) 

      But there is another, in which a bunch of subtractions of parts of the date:

       SELECT dateadd(ms, -datepart(ms,getdate()),dateadd(s, -datepart(s,getdate()), dateadd(mi, -datepart(mi,getdate()),dateadd(hh, -datepart(hh,getdate()),DATEADD(DAY, 1-DATEPART(WEEKDAY, getdate()), getdate()))))) 

      What do you like more - choose.