SQL Server 取日期时只要年月或年月日
select CONVERT(varchar(7) ,getdate(), 120) as 'Date' from 表名;--只取年月且日期格式为 xxxx-xx
select CONVERT(varchar(12) ,getdate(), 120) as 'Date' from 表名;--只取年月日且日期格式为 xxxx-xx-xx
CONVERT负责截取位数,120代表日期格式
日期格式对照:
101 xx/xx/xxxx(Month/Date/Year)
102 xxxx.xx.xx(Year.Month.Date)
103 xx/xx/xxxx(Date/Month/Year)
104 xx.xx.xxxx(Date.Month.Year)
105 xx-xx-xxxx(Date-Month-Year)
106 xx xx xxxx(Date Month Year)
107 xx xx,xxxx(Date Month,Year)
111 xxxx/xx/xx(Year/Month/Date)
112 xxxxxxxx(YearMonthDate)
120 xxxx-xx-xx(Year-Month-Date)
..........