How to find the starting date of current month in SQL Server 2005 ?
如何在SQL Server 2005中找到当前月份的起始日期?
4 个解决方案
#1
4
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
对于最后一天和其他时间段,请参见这里:http://wiki.lessthandot.com/index.php/how_find_the_first_and_last_days_in_years%2c_months_etc
#2
0
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
获得每月第一天的功能。
#3
0
DECLARE @currentmonthstart datetime
SET @currentmonthstart = DATEADD(DD, -DATEPART(DD, GETDATE())+1, getdate())
PRINT @currentmonthstart
#4
0
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))
#1
4
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
对于最后一天和其他时间段,请参见这里:http://wiki.lessthandot.com/index.php/how_find_the_first_and_last_days_in_years%2c_months_etc
#2
0
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
获得每月第一天的功能。
#3
0
DECLARE @currentmonthstart datetime
SET @currentmonthstart = DATEADD(DD, -DATEPART(DD, GETDATE())+1, getdate())
PRINT @currentmonthstart
#4
0
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))