PostgreSQL将月份名称转换为数字 [英] PostgreSQL convert month name to number

查看:423
本文介绍了PostgreSQL将月份名称转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,该查询以月和年为单位返回一个字段,例如 2015年11月,我想获取该月的数字,在这里我必须将数字获取为 11。

I have a query that returns a field as month and year for example "Nov 2015" I want to get the number for the month, here I have to get number as "11".

推荐答案

您可以使用to_date函数,该函数可以将特定格式的输入解析为实际日期。然后,您可以从该日期中提取月份。

You can use the to_date function that can parse input in a certain format into a 'real' date. Then with this date you can extract the month from it.

select EXTRACT(MONTH FROM to_date('Nov 2015', 'Mon YYYY'))

请参见 http://www.postgresql.org/docs/current/static/functions-formatting.html 了解格式语法和 http://www.postgresql.org/docs/current/static/functions-datetime。 html 用于其他datetime函数等。

See http://www.postgresql.org/docs/current/static/functions-formatting.html for the formatting syntax and http://www.postgresql.org/docs/current/static/functions-datetime.html for the other datetime functions etc..

这篇关于PostgreSQL将月份名称转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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