Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SELECT
sdomain.SalesOrg ,
sdomain.Id,
sdomain.Phase,
SdoMain.InitiationDate as "CASOrderStartTime"
From
SDOMAIN
WHERE
SdoMain.Status<>'d'
and sdomain.InitiationDate<=Getdate()-1
and sdomain.Phase in ('Submitted','OnRoute')

order by sdomain.InitiationDate

What I have tried:

In the above query,I want to get the result of one date prior of the today's date.So I have used InitiationDate<=Getdate()-1 .But on monday i want to take the friday's date (suppose today is 27 feb,17 i.e.monday and I want that this query should take the friday's date i.e.(24 feb,17).Is there any function or any way how can I do this??
Please help asap/
Thanks in advance!!!
Posted
Updated 27-Feb-17 11:56am

Try this:
declare @date datetime;
select @date =
case
   when datepart(weekday, getdate()) = 2 then getdate()-3
   else getdate() - 1
end;
select @date
DATEPART (Transact-SQL)[^]
 
Share this answer
 
v3
Comments
CHill60 27-Feb-17 10:20am    
4'd - I think you need to use -3 and -1 to correctly fit the OP's requirement?
Peter Leow 27-Feb-17 10:47am    
Thank you. That was my oversight. Corrected.
CHill60 27-Feb-17 10:48am    
Upgraded vote to 5!
Peter Leow 27-Feb-17 10:53am    
Thank you.
Member 12965461 28-Feb-17 12:29pm    
Thanks to all for your help.
It worked.
Quote:
How to get date of friday if I am running the query on monday?

I don't understand your problem.
You already know how to go to previous day, with Getdate()-1, aka from today the 27, you check the 26.
And you wonder from today the 27, you check the 24, are you unable to count to 3 and get Getdate()-3 ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900