Helper Helper - 1 month ago 5
SQL Question

How to get day or year number from timestamp column in postgres

I have a Timestamp column in a table like this on postgres

CreatedAt

2016-10-26 07:33:51.029
2016-11-01 08:39:12.322


I need to get day like

SELECT day number or may be month number
FROM "MyTable";


expected output would be

day

26
01

Answer

You can try

SELECT to_char("your column",'DD') as "day" 
FROM "MyTable";

more at [https://www.postgresql.org/docs/9.1/static/functions-formatting.html]

Comments