复制代码 代码如下:
CREATE FUNCTION [dbo].[udf_FirstDayOfMonth]
(
@Date DATE
)
RETURNS DATETIME
AS
BEGIN
RETURN CAST(DATEADD(day,1 - DAY(@Date), @Date) AS DATETIME)
END
复制代码 代码如下:
CREATE FUNCTION [dbo].[udf_FirstDayOfMonth]
(
@Date DATE
)
RETURNS DATETIME
AS
BEGIN
RETURN DATEADD(MONTH,DATEDIFF(MONTH,0,@Date),0)
END
复制代码 代码如下:
CREATE FUNCTION [dbo].[udf_FirstDayOfMonth]
(
@Date DATE
)
RETURNS DATETIME
AS
BEGIN
DECLARE @y NVARCHAR(4) = CAST(YEAR(@Date) AS NVARCHAR(4))
DECLARE @m NVARCHAR(2) = CAST(MONTH(@Date) AS NVARCHAR(2))
RETURN CAST((@y + N'-' + @m + N'-01') AS DATETIME)
END
复制代码 代码如下:
CREATE FUNCTION [dbo].[udf_FirstDayOfMonth]
(
@Date DATE
)
RETURNS DATETIME
AS
BEGIN
DECLARE @ym NVARCHAR(10) = CONVERT(varchar(8),GETDATE(),23)
RETURN CAST((@ym + N'01') AS DATETIME)
END
新闻热点
疑难解答