B
B
blainethemono2015-10-15 12:38:11
SQL Server
blainethemono, 2015-10-15 12:38:11

How to subtract 1 day from a quarter?

Hello!
You need to get data with the creation date "greater than or equal to the current quarter - 1 day". Tried like this:

datepart(dd, CreatedDate) >= dateadd(dd, -1, DATEPART(qq, getdate()))
and datepart(yy, CreatedDate) = datepart(yy, GETDATE())

But it gives out data for half a year. Can anyone advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Polozov, 2015-10-15
@blainethemono

select  dateadd(qq, datediff(qq, 0, getdate()), 0)  -- начало текущего квартала
    
select  dateadd(dd, -1, dateadd(qq, datediff(qq, 0, getdate()), 0) )  -- начало текущего квартала - 1 день.
    
-- CreatedDate >= dateadd(dd, -1, dateadd(qq, datediff(qq, 0, getdate()), 0) )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question