use*_*189 11 sql postgresql select timestamp
How to get the date and time only up to minutes, not seconds, from timestamp in PostgreSQL. I need date as well as time.
For example:
2000-12-16 12:21:13-05
Run Code Online (Sandbox Code Playgroud)
From this I need
2000-12-16 12:21 (no seconds and milliseconds only date and time in hours and minutes)
Run Code Online (Sandbox Code Playgroud)
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.
Please help me.
Erw*_*ter 22
为了得到date从timestamp(或timestamptz)一个简单的铸件是最快的:
SELECT now()::date
Run Code Online (Sandbox Code Playgroud)
无论哪种方式,您都可以date根据当地时区获得.
如果你想text在一定的格式,去与to_char()像提供@davek.
如果要将a的值截断(向下舍入)timestamp到一个时间单位,请使用date_trunc():
SELECT date_trunc('minute', now());
Run Code Online (Sandbox Code Playgroud)
dav*_*vek 20
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
Run Code Online (Sandbox Code Playgroud)
对于格式化,您可以使用这些:
http://www.postgresql.org/docs/9.1/static/functions-formatting.html
例如
select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI') ...
Run Code Online (Sandbox Code Playgroud)
这应该足够了:
select now()::date, now()::time
, pg_typeof(now()), pg_typeof(now()::date), pg_typeof(now()::time)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
79131 次 |
| 最近记录: |