pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Problems with to_char(created, 'WW')
3+ messages / 3 participants
[nested] [flat]

* Problems with to_char(created, 'WW')
@ 2002-10-24 10:51  Andreas Joseph Krogh <andreak@officenet.no>
  0 siblings, 2 replies; 3+ messages in thread

From: Andreas Joseph Krogh @ 2002-10-24 10:51 UTC (permalink / raw)
  To: pgsql-sql

Hi.
I have the following schema in PostgreSQL-7.2.2:

CREATE TABLE session (
	session_id varchar(256) NOT NULL PRIMARY KEY,
	created timestamp DEFAULT 'now' NOT NULL,
	last_accessed timestamp NOT NULL,
	destroyed timestamp NOT NULL,
	username varchar -- Allow sessions from not logged in users
);

Now I run this query to extract the week numbers:

janerik=# select created, to_char(created, 'WW') as week from session WHERE
username IS NULL ORDER BY week;
 
          created           | week 
----------------------------+------
 2002-09-24 11:23:21.206+02 | 39
 2002-09-24 18:19:06.304+02 | 39
 2002-09-25 10:50:27.139+02 | 39
 2002-09-30 12:32:06.898+02 | 39
 2002-10-01 16:26:41.122+02 | 40
 2002-10-04 13:47:02.922+02 | 40
 2002-10-04 21:28:13.409+02 | 40
 2002-10-04 17:35:50.954+02 | 40
 2002-10-04 23:31:27.566+02 | 40
 2002-10-04 23:34:18.286+02 | 40
 2002-10-07 13:48:14.275+02 | 40
 2002-10-07 13:50:04.352+02 | 40
 2002-10-07 14:10:01.441+02 | 40
 2002-10-11 12:57:53.458+02 | 41
 2002-10-11 13:24:49.124+02 | 41
 2002-10-13 16:26:52.546+02 | 41
 2002-10-14 23:50:51.131+02 | 41
 2002-10-15 14:54:12.341+02 | 42
 2002-10-15 15:09:36.84+02  | 42
 2002-10-15 15:21:26.59+02  | 42
 2002-10-20 12:14:05.203+02 | 42
 2002-10-20 20:19:44.309+02 | 42
 2002-10-21 14:23:31.425+02 | 42
 2002-10-22 12:12:31.63+02  | 43
 2002-10-23 14:00:18.478+02 | 43
(25 rows)

Now - my question is, why is monday 21. in week 42, but tuesday 22. in week 
43?

-- 
Andreas Joseph Krogh <andreak@officenet.no>
- There are 10 kinds of people in the world, those that can do binary
  arithmetic and those that can't.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Problems with to_char(created, 'WW')
@ 2002-10-24 11:08  Karel Zak <zakkr@zf.jcu.cz>
  parent: Andreas Joseph Krogh <andreak@officenet.no>
  1 sibling, 0 replies; 3+ messages in thread

From: Karel Zak @ 2002-10-24 11:08 UTC (permalink / raw)
  To: Andreas Joseph Krogh <andreak@officenet.no>; +Cc: pgsql-sql

On Thu, Oct 24, 2002 at 12:51:35PM +0200, Andreas Joseph Krogh wrote:
> 
> janerik=# select created, to_char(created, 'WW') as week from session WHERE
> username IS NULL ORDER BY week;

 Please, see docs and 'IW' (ISO week).

    Karel

-- 
 Karel Zak  <zakkr@zf.jcu.cz>
 http://home.zf.jcu.cz/~zakkr/
 
 C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Problems with to_char(created, 'WW')
@ 2002-10-24 11:19  Tomasz Myrta <jasiek@klaster.net>
  parent: Andreas Joseph Krogh <andreak@officenet.no>
  1 sibling, 0 replies; 3+ messages in thread

From: Tomasz Myrta @ 2002-10-24 11:19 UTC (permalink / raw)
  To: Andreas Joseph Krogh <andreak@officenet.no>; +Cc: pgsql-sql

Uz.ytkownik Andreas Joseph Krogh napisa?:
> 
> Now - my question is, why is monday 21. in week 42, but tuesday 22. in week 
> 43?

Read the documentation - 4.7. Data Type Formatting Functions
"WW - week number of year (1-53) where first week start on the first day 
of the year"

Year 2002 started on Tuesday, so monday is still week 42, but tuesday is 
week 43.

Tomasz Myrta




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-10-24 11:19 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-10-24 10:51 Problems with to_char(created, 'WW') Andreas Joseph Krogh <andreak@officenet.no>
2002-10-24 11:08 ` Karel Zak <zakkr@zf.jcu.cz>
2002-10-24 11:19 ` Tomasz Myrta <jasiek@klaster.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox