How to find the s开发者_StackOverflow中文版tarting date of current month in SQL Server 2005 ?
one way
SELECT DATEADD(mm, DATEDIFF(mm, 0, getdate()), 0) AS FirstDayOfMonth
for last day and other time periods, see here: http://wiki.lessthandot.com/index.php/How_to_find_the_first_and_last_days_in_years%2C_months_etc
DECLARE @mydate DATETIME
SELECT @mydate = GETDATE()
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101) AS Date_Value
Get First Day of the Month Function
DECLARE @currentmonthstart datetime
SET @currentmonthstart = DATEADD(DD, -DATEPART(DD, GETDATE())+1, getdate())
PRINT @currentmonthstart
There will be loads of ways to do this, and this is one of them:
select convert(datetime,convert(varchar(10),getdate() - day(getdate()) + 1,120))
精彩评论