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
Legacy Comments
Brett
2004-02-28 |
re: Come on Weekend! You're a tard! Only kidding....Nice to see someone else on EE with a decent name for change :) Brett |
scody
2004-03-02 |
re: Come on Weekend! You stole my blog name... you ... blogname theif! :) select * from blogs_of_the_world where blog_name like '%Disconnected Ramblings%' |
Brett
2004-03-02 |
Come on Weekend! We could start a club for the lucidly challenged! |
abcdefgh
2006-05-09 |
re: Come on Weekend! "select (dateadd(day,1,date(LPD_LTRY_PRRTN_DT) ) - 1 days) from LPD_LOTTRY_PRO_DT |