K
K
kidar22016-08-25 06:54:56
PostgreSQL
kidar2, 2016-08-25 06:54:56

How to get week number from american style date?

There is such a request:
select EXTRACT(WEEK from '2016-01-01'::TIMESTAMP)
which returns 53. I.e. works according to the iso standard.
Is it possible to somehow work on am. style? Those. to

select EXTRACT(WEEK from '2016-01-01'::TIMESTAMP) => 1
select EXTRACT(WEEK from '2016-01-03'::TIMESTAMP) => 2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2016-08-25
@kidar2

"American style" is when the date is in the middle? Then like this:

SELECT EXTRACT(WEEK from to_timestamp('2016-25-08', 'YYYY-DD-MM'));

A
Alexey Aleksin, 2016-08-25
@leroyleroy

www.w3schools.com/sql/func_date_format.asp
Here is a nice function, have a look

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question