select case when
left(datepart(day,getdate()),1)=4 then concat(datepart(day,getdate()),'th',' of ',DATENAME(month,GETDATE()),' ',datepart(year,getdate()))
end
DECLARE @day int = datepart(day,getdate())
SELECT CONCAT(@day,
CASE WHEN @day=1 OR @day=21 OR @day=31 THEN 'st'
WHEN @day=2 OR @day=22 THEN 'nd'
WHEN @day=3 OR @day=23 THEN 'rd' ELSE 'th' END, ' of ',DATENAME(month,GETDATE()),' ',datepart(year,getdate()) )AS 'Date'
CREATE FUNCTION [dbo].[fnc_GetDateString]
(
@date DATETIME
)
RETURNS nvarchar(100)
AS
BEGIN
--DECLARE @date DATETIME = '2020-08-31'
DECLARE @day int = datepart(day,@date)
DECLARE @DateString nvarchar(100)
SET @DateString = CONCAT(@day,
CASE WHEN @day=1 OR @day=21 OR @day=31 THEN 'st'
WHEN @day=2 OR @day=22 THEN 'nd'
WHEN @day=3 OR @day=23 THEN 'rd' ELSE 'th' END, ' of ',DATENAME(month,@date),' ',datepart(year,@date) )
RETURN @DateString
END
1条答案
按热度按时间ryoqjall1#
会给你这样的东西。
编辑:如果你把它作为函数,并把它作为参数传递日期,你几乎可以在任何地方使用它。然后需要用参数名替换getdate()