sql server中获取date类的年月日(如何取中间的月分)

   更新日期:2024.05.02

可用month函数获取月份。

测试方法:

1、创建一个含有date类型的表,并在表中插入数据(数据日期为当前时间):

create table test
(id int,
begin_date date)

insert into test values (1,getdate())

2、执行语句,获取月份:

select MONTH(begin_date) from test

3、执行结果:



select * from table where  DATEPART(month, 日期的字段) =12
或者
select * from table where month(日期字段)=12


我感觉日期就是字符串,用字符串的截取方式查找行么

datepart()函数

相关链接

欢迎反馈与建议,请联系电邮
2024 © 视觉网