Home >Database >Mysql Tutorial >get year from a postgresql DATE

get year from a postgresql DATE

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 14:58:301309browse

get year from a postgresql DATE 1、如果所在的列属性 mydate 本身为 DATE 类型,则使用: [sql] SELECT EXTRACT(year FROM mydate) FROM mytable; 2、如果所在的列属性 mydate 为 varchar 类型,则先使用 to_date()将其转换为 DATE类型,然后在使用 EXTRAC

get year from a postgresql DATE

 

1、如果所在的列属性 mydate 本身为 DATE 类型,则使用:

 

[sql] 

SELECT EXTRACT(year FROM mydate) FROM mytable;  

 

2、如果所在的列属性 mydate 为 varchar 类型,则先使用

 

 to_date()将其转换为 DATE类型,然后在使用 EXTRACT year:

 

[sql] 

SELECT EXTRACT(year FROM to_date(mydate, )) FROM mytable;  

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:轻松理解数据库三范式Next article:mongodb聚合函数