如何从 PostgreSQL 选择查询中的时间戳获取日期和时间? [英] How to get the date and time from timestamp in PostgreSQL select query?
本文介绍了如何从 PostgreSQL 选择查询中的时间戳获取日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 PostgreSQL 中的时间戳中获取最多分钟而不是秒的日期和时间.我需要日期和时间.
How to get the date and time only up to minutes, not seconds, from timestamp in PostgreSQL. I need date as well as time.
例如:
2000-12-16 12:21:13-05
从这里我需要
2000-12-16 12:21 (no seconds and milliseconds only date and time in hours and minutes)
从带有时区字段的时间戳,比如 update_time
,我如何使用 PostgreSQL 选择查询获取日期和时间.
From a timestamp with time zone field, say update_time
, how do I get date as well as time like above using PostgreSQL select query.
请帮帮我.
推荐答案
postgresql 提供了大量的日期时间函数:
There are plenty of date-time functions available with postgresql:
在此处查看列表
http://www.postgresql.org/docs/9.1/静态/函数-datetime.html
例如
SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40');
Result: 16
对于格式化,您可以使用这些:
For formatting you can use these:
http://www.postgresql.org/docs/9.1/静态/函数格式.html
例如
select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI') ...
这篇关于如何从 PostgreSQL 选择查询中的时间戳获取日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文