如何获取sql数据中时间的月份、年份(类型date)
可用自带函数month来实现。
如:
创建表及插入数据:
create table test
(id int,
begindate datetime)
insert into test values (1,"2015-01-01")
insert into test values (2,"2015-02-01")
执行sql语句,获取月份:
select id,MONTH(begindate) as month from test
执行sql语句,获取年份:
select id,YEAR(begindate) as year from test
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: EL表达式及${对象}
- 下一篇: PHP中循环结构之foreach循环语句(下标和值)