Prev: Smo and SQLCMD commands
Next: Assembly Re-distribution
From: Muhammad Bilal on 31 Jan 2010 16:12 Hi. I want to to know the date of the day Monday of the current weak. Suppose if today is 31 Jan 2010. It return the date of Monday as 25 Jan 2010. Regards, Muhammad Bilal
From: Plamen Ratchev on 31 Jan 2010 22:16 You can use the following formula based on offset from well known Monday date: DECLARE @dt DATETIME; SET @dt = '20100131'; -- 31 Jan 2010 -- Jan 1 2009 is Monday SELECT DATEADD(DAY, (DATEDIFF(DAY, '19000101', @dt) / 7) * 7, '19000101') AS monday_date; /* monday_date ----------------------- 2010-01-25 00:00:00.000 */ -- Plamen Ratchev http://www.SQLStudio.com
From: Uri Dimant on 1 Feb 2010 02:43 Muhammad Anothe method is SELECT '20100131' - datepart(weekday, CAST('20100131'AS DATETIME) + @@datefirst - 1) + 1 as Mon See @@datefirst vairable may not be the same for all regions "Muhammad Bilal" <MuhammadBilal(a)discussions.microsoft.com> wrote in message news:91C3680E-3331-49D3-8CAF-9E0B2A032D66(a)microsoft.com... > Hi. > > I want to to know the date of the day Monday of the current weak. > Suppose if today is 31 Jan 2010. It return the date of Monday as 25 Jan > 2010. > > > > Regards, > Muhammad Bilal
|
Pages: 1 Prev: Smo and SQLCMD commands Next: Assembly Re-distribution |