select to_char(current_timestamp, 'YYYY-WW');

Started by Alexander Farberover 15 years ago4 messagesgeneral
Jump to latest
#1Alexander Farber
alexander.farber@gmail.com

Hello,

sorry for the stupid question, but why has the week number changed
from 44 to 45 this night? It is Friday, 2010-11-05 01:10, but I get now:

pref=> SELECT to_char(current_timestamp, 'YYYY-WW');
to_char
---------
2010-45
(1 row)

pref=> SELECT CURRENT_DATE;
date
------------
2010-11-05
(1 row)

pref=> SELECT CURRENT_TIME;
timetz
-------------------
01:12:00.65546+01
(1 row)

# date
Fri Nov 5 01:13:57 CET 2010
# cat /etc/*release
CentOS release 5.5 (Final)
# rpm -qa|grep -i postgres
compat-postgresql-libs-4-1PGDG.rhel5
postgresql-libs-8.4.5-1PGDG.rhel5
compat-postgresql-libs-4-1PGDG.rhel5
postgresql-docs-8.4.5-1PGDG.rhel5
postgresql-8.4.5-1PGDG.rhel5
postgresql-libs-8.4.5-1PGDG.rhel5

Regards
Alex

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alexander Farber (#1)
Re: select to_char(current_timestamp, 'YYYY-WW');

Alexander Farber <alexander.farber@gmail.com> writes:

sorry for the stupid question, but why has the week number changed
from 44 to 45 this night?

WW is defined as starting the first week on the first day of the year.
2010 started on a Friday so the week number increments on Fridays.

There are some other format codes with different behavior ...

regards, tom lane

#3Alexander Farber
alexander.farber@gmail.com
In reply to: Tom Lane (#2)
Re: select to_char(current_timestamp, 'YYYY-WW');

On Fri, Nov 5, 2010 at 1:21 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

WW is defined as starting the first week on the first day of the year.
2010 started on a Friday so the week number increments on Fridays.

There are some other format codes with different behavior ...

Thank you, that is what I thought

But is there a format code for a week starting on Sunday or Monday?

Sorry, I can't find it at
http://www.postgresql.org/docs/8.4/interactive/functions-formatting.html

Regards
Alex

#4Alexander Farber
alexander.farber@gmail.com
In reply to: Alexander Farber (#3)
Re: select to_char(current_timestamp, 'YYYY-WW');

I will try YYYY-IW

On Fri, Nov 5, 2010 at 1:28 AM, Alexander Farber
<alexander.farber@gmail.com> wrote:

Show quoted text

But is there a format code for a week starting on Sunday or Monday?

Sorry, I can't find it at
http://www.postgresql.org/docs/8.4/interactive/functions-formatting.html