xyray
xyray

Reputation: 45

Oracle week of the year

Why 12/16/2013 and 12/17/2013 are in different week?

alter session set NLS_TERRITORY=AMERICA;
select to_char(to_date('12-16-2013', 'mm-dd-yyyy'),'ww'),to_char(to_date('12-17-2013', 'mm-dd-yyyy'),'ww') from dual

Upvotes: 4

Views: 3846

Answers (1)

OldProgrammer
OldProgrammer

Reputation: 12179

If you look at the formatting models documentation, it states:

  • WW - Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
  • W - Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.

01/01/2013 started on a Tuesday last year, not the first day of week. So in your test case, 12/17/2013 was on a Tuesday also, and a new "week" as oracle calculates it. Certainly, non-obvious.

Upvotes: 3

Related Questions