SELECT DateAdded,
CAST(DateAdded AS date USING 'mm:dd') AS MonthDay
FROM Products;
“AS”继续收到错误。
答案 0 :(得分:1)
使用Month
和Day
功能从日期类型中提取month
和day
。试试这个。
SELECT DateAdded,
Convert(varchar(2),month(DateAdded))+':'+
Convert(varchar(2),Day(DateAdded)) As MonthDay
FROM Products;
或在101
中使用convert
样式,并将/
替换为:
SELECT DateAdded,
Replace(Left(Convert(varchar(20),DateAdded,101),4),'/',':') As MonthDay
FROM Products;
或Datepart
SELECT DateAdded,
Convert(varchar(2),Datepart(Month,DateAdded))+':'+
Convert(varchar(2),Datepart(Day,DateAdded)) As MonthDay
FROM Products;
答案 1 :(得分:1)
以下是使用演员
的一种可能解决方案SELECT
DateAdded,
CAST(DateAdded AS date) AS Date,
CAST(DateAdded AS time) AS Time,
right('0' + cast(month(DateAdded) as varchar(2)),2) + ':'
+ right('0' + cast(day(DateAdded) as varchar(2)),2) AS MonthDay
FROM Products