我无法运行此功能,是否有任何更改:
CREATE FUNCTION [GetFirstDateofMonth]
(@Date as DateTime)
RETURNS DateTime AS
BEGIN
Declare @FirstDate DateTime
Set @FirstDate = DateAdd(Day, 1, @Date - Day(@Date) + 1) -1
RETURN @FirstDate
END
CREATE FUNCTION [GetLastDateofMonth]
(@Date as DateTime)
RETURNS DateTime AS
BEGIN
Declare @LastDate DateTime
Set @LastDate = DateAdd(Month, 1, @Date - Day(@Date) + 1) -1
RETURN @LastDate
END
答案 0 :(得分:0)
假设你想要它相对于“现在”:
select subdate(adddate(last_day(now()), 1), interval 2 month)
将now()
替换为您想要的任何内容,如果它相对于“now”以外的某个日期