Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Oracle returning incorrect day of the week

pmdciDec 14 2013 — edited Dec 14 2013

Hi there,

I have a table named Performance, which includes a date field named PDATE, some other attributes such as title, etc, and a field named WEEKDAY, which includes the numerical value for the day of the week. Here is an example:

PER#P#THEATRE#WEEKDAYPDATEPHOURPMINUTECOMMENTS
111102-MAR-101930Normal evening time
211203-MAR-101930Normal evening time
5866304-MAR-101930Normal evening time
511405-MAR-101930Normal evening time

I went to verify the day of the week in a calendar (in fact I checked more than one) and I noticed that the Weekday value seems incorrect. For instance, the 2nd of March was a Tuesday so I would expect WEEKDAY to say 3 (considering Sunday to be the 1st day of the week, which is the universal norm), or perhaps 2 (considering Monday to be the 1st day of the week).

First thing that came to mind is, since the WEEKDAY is a number field which has been pre-populated, the person who populated it made a mistake.

So I went to verify this by running a query that would give me the correct day of the week by extracting it from the PDATE field:

SELECT DISTINCT pdate, EXTRACT(year from pdate) year,

to_char(to_date(pdate,'DD/MM/YYYY'),'DY') weekdaycalc, weekday

FROM ops$yyang00.Performance

ORDER BY pdate

And to my astonishment, I got the following table as a return:

PDATEYEARWEEKDAYCALCWEEKDAY
02-MAR-102010SUN1
03-MAR-102010MON2
04-MAR-102010TUE3
05-MAR-102010WED4
06-MAR-102010THU5
07-MAR-102010FRI6
08-MAR-102010SAT7
09-MAR-102010SUN1
10-MAR-102010MON2

As you can see, all of the above WEEKDAYCALC values are incorrect, and seem to match the incorrect values in WEEKDAY.

I could perhaps understand some weird WEEKDAY numbering if there is some general database setting where I could specify any day of the week to be the first day. However, I can't think of any logical explanation on why Oracle would call a Tuesday Sunday.

Could someone please advise what I mght be doing wrong? This is driving me insane!

Thank you in advance for all the help and support.

Regards,

P.

This post has been answered by Frank Kulash on Dec 14 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 11 2014
Added on Dec 14 2013
13 comments
2,948 views