如何从PostgreSQL选择查询中的时间戳获取日期和时间? [英] How to get the date and time from timestamp in PostgreSQL select query?

查看:1325
本文介绍了如何从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/static/functions -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/static/functions-formatting.html

例如

select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI') ...

这篇关于如何从PostgreSQL选择查询中的时间戳获取日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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