Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get First Sunday of APRIL and Last Sunday

Author  Topic 

avmreddy17
Posting Yak Master

180 Posts

Posted - 2006-03-09 : 13:43:14
I have time in the Integer Field ( The Field Represents milliseconds Past Midnight w.r.t GMT )
I want to have a function so that I can pass this integer field to the function and get the DATETIME Value.

In that function I want to code it for Day light Saving time also

How to get First Sunday of APRIL
and Last Sunday of OCTOBER

Eg

ms past midnight w.r.t 47602656
SELECT 47602656 , DATEADD(hh , -5 , DATEADD(MS, 47602656 , CONVERT(VARCHAR(10), GETDATE(), 101)) )

Thx
Venu

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-03-09 : 13:57:46
This should do it. Function F_START_OF_WEEK is available in Script Library forum.
select 
FIRST_SUNDAY_IN_APRIL =
dbo.F_START_OF_WEEK('20060407',1),
LAST_SUNDAY_IN_OCTOBER =
dbo.F_START_OF_WEEK('20061031',1)

Results:

FIRST_SUNDAY_IN_APRIL LAST_SUNDAY_IN_OCTOBER

------------------------ ------------------------
2006-04-02 00:00:00.000 2006-10-29 00:00:00.000

(1 row(s) affected)


CODO ERGO SUM
Go to Top of Page
   

- Advertisement -