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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Get 1st day when month / year passed

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-08-01 : 16:34:05
An easy way to get the first day when month/year is passed as parm?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-01 : 16:37:34
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, @Param), 0) AS theFirstDayOfYear,
DATEADD(MONTH, DATEDIFF(MONTH, 0, @Param), 0) AS theFirstDayOfMonth



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-01 : 16:38:11
SELECT DATEADD(MONTH, 12 * @Year - 22801 + @Month, 0) AS theFirstOfMonth


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-08-01 : 16:57:22
If I now do this:

declare @Param as datetime
declare @theFirstDayOfMonth as datetime
set @Param = 2009-07 ???????
set @theFirstDayOfMonth = DATEADD(MONTH, DATEDIFF(MONTH, 0, @Param), 0)

What would I set the @Param to?

Thanks.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-02 : 08:44:17
Doesn't matter.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -