如何从 PostgreSQL 选择查询中的时间戳获取日期和时间?

编程入门 行业动态 更新时间:2024-10-27 08:30:00
本文介绍了如何从 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:

在此处查看列表

www.postgresql/docs/9.1/静态/函数-datetime.html

例如

SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40'); Result: 16

对于格式化,您可以使用这些:

For formatting you can use these:

www.postgresql/docs/9.1/静态/函数格式.html

例如

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

更多推荐

如何从 PostgreSQL 选择查询中的时间戳获取日期和时间?

本文发布于:2023-10-16 12:28:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   日期   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!