如何使用sql查询从字段中仅获取月份? [英] How can i get only month from a field using sql query?

查看:67
本文介绍了如何使用sql查询从字段中仅获取月份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表格中,我有一个包含日期的字段,我只想从中取一个月
有可能吗?

In my table i have one field which contains the date, i want to take only month from that
is it possible?
similarly how can i take month from system date?

推荐答案

您可以使用DATEPART函数获取月份号,或者使用DATENAME函数获取月份名称. >
You can use the DATEPART function to get the month number or DATENAME function to get the month name.
select datepart(month,Mydate), datename(month,Mydate)


来源 [


Source[^]

See Solution 2 for the oracle answer. (I didn''t see that tag, sorry)


对于 SQL Server
SELECT MONTH(MyDateColunm) from MyTable;



获取系统/当前月份.



To get System/Current Month.

SELECT MONTH(GETDATE());



对于 Oracle



For Oracle

select to_char(MyDateColunm, 'Month') from MyTable;


获取系统/当前月份.


To get System/Current Month.

select to_char(sysdate, 'Month') from dual;


这篇关于如何使用sql查询从字段中仅获取月份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆