Christopher Tyler

Date Functions

n PostgreSQL, you can easily extract values from date columns. You will see the most used date functions below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
SELECT
date_part('year',hire_date) AS year
,date_part('month',hire_date) AS month
,date_part('day',hire_date) AS day
,date_part('dow',hire_date) AS dayofweek
,to_char(hire_date,'Dy') AS day_name
,to_char(hire_date,'Month') AS month_name
,hire_date
FROM employees

| year | month | day | dayofweek | day_name | month_name | hire_date  |
| ---- | ----- | --- | --------- | -------- | ---------- | ---------- |
| 2006 | 4     | 20  | 4         | Thu      | April      | 2006-04-20 |
| 2009 | 1     | 26  | 1         | Mon      | January    | 2009-01-26 |
| 2010 | 5     | 17  | 1         | Mon      | May        | 2010-05-17 |

<< Previous Post

|

Next Post >>

#Postgresql #Date_part #To_char