x002548's Blog

Not Just a Number - Brett Kaiser
posts - 89, comments - 586, trackbacks - 39

Come on Weekend!

CREATE FUNCTION Weekend (@Date Datetime)
RETURNS datetime
AS
BEGIN
DECLARE @Weekend datetime

IF (SELECT 6-DATEPART(dw,@Date)) < 0
  BEGIN
 SELECT @Weekend =
   CONVERT(datetime
 , CONVERT(varchar(10)
 , (DATEADD(dd
 , 13-DATEPART(dw,@Date)
 , @date)), 120) + ' 17:00:00')
  END
 ELSE
  BEGIN
--Handles Friday itself
IF (SELECT 6-DATEPART(dw,@Date)) = 0
  BEGIN  --for after 1700 but before midnight
    IF (SELECT DATEDIFF(ss, @date
  , CONVERT(datetime, CONVERT(varchar(10)
  , @Date, 120)) + ' 17:00:00')) < 0
  BEGIN
  SELECT @Weekend = CONVERT(datetime
   , CONVERT(varchar(10)
   , (DATEADD(dd, 13-DATEPART(dw,@Date)
   , @date)), 120) + ' 17:00:00')
  END
 ELSE   --for before 1700 on Friday
  BEGIN
  SELECT @Weekend = CONVERT(datetime
  , CONVERT(varchar(10), @Date, 120) + ' 17:00:00')
  END
 END
 ELSE  --Handles days before Friday
 BEGIN
 SELECT @Weekend = CONVERT(datetime
  , CONVERT(varchar(10)
  , (DATEADD(dd, 6-DATEPART(dw,@Date)
  , @Date)), 120) + ' 17:00:00')
 END
END
Return @Weekend
END
GO

SELECT DATEDIFF(mi, getdate(), dbo.Weekend(GetDate()))/60.00 As Hours_till_Margarittaville

 

Special thanks to Preston

 

http://www.sqlteam.com/forums/pop_profile.asp?mode=display&id=5566

 

 


 

 

Print | posted on Friday, February 27, 2004 11:09 AM | Filed Under [ Disconnected Ramblings ]

Feedback

Gravatar

# re: Come on Weekend!

You're a tard!

Only kidding....Nice to see someone else on EE with a decent name for change :)

Brett
2/28/2004 12:12 PM | Brett
Gravatar

# re: Come on Weekend!

You stole my blog name...
you ... blogname theif!

:)

select * from blogs_of_the_world where blog_name like '%Disconnected Ramblings%'



3/2/2004 1:23 PM | scody
Gravatar

# Come on Weekend!

We could start a club for the lucidly challenged!

3/2/2004 1:42 PM | Brett
Gravatar

# re: Come on Weekend!

"select (dateadd(day,1,date(LPD_LTRY_PRRTN_DT) ) - 1 days) from LPD_LOTTRY_PRO_DT
5/9/2006 2:53 AM | abcdefgh
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET