我在postgres上的表中有一个Timestamp列
CreatedAt
2016-10-26 07:33:51.029
2016-11-01 08:39:12.322
我需要像
这样的日子SELECT day number or may be month number
FROM "MyTable";
预期输出
day
26
01
答案 0 :(得分:4)
使用extract()
功能:
select extract(day from createdat) as day,
extract(year from createdat) as year
from "MyTable";
手册中的更多详细信息:https://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
答案 1 :(得分:0)
你可以尝试
SELECT to_char("your column",'DD') as "day"
FROM "MyTable";
更多https://www.postgresql.org/docs/current/static/functions-formatting.html