Return the Monday in current week

Posted on 2015-01-09
Last Modified: 2015-01-09
Guys, I am after a piece of sql that I can add to a report that depending on sysdate it will return the MONDAY of that week.

ie today is 9th January so the sysdate is 09/01/2015 the Monday is 05/01/2015

So I would like to have a sql script to show this.

Any Ideas

Thank you
Question by:DarrenJackson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 77

Accepted Solution

slightwv (䄆 Netminder) earned 400 total points
ID: 40540227
Try this:  trunc(sysdate,'IW')
LVL 74

Assisted Solution

sdstuber earned 100 total points
ID: 40540230
select next_day(sysdate-7,'Monday') from dual

trunc  or to_char as needed

Author Comment

ID: 40540247
sdstuber I get an error but the example slightwv has suggested is working great.

That example seems way to simple :)  am I right in thinking any day of the week from Monday to sunday if I run it the return value will be the Monday of the current week?

Thanks for the quick response
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 40540248
Sorry sdstuber the error I get is " ora-01846 not a valid day of the week"
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40540250
>>am I right in thinking any day of the week from Monday to sunday if I run it the return value will be the Monday of the current week?

Mock up a simple test and see.  replace sysdate with sysdate-<some number> or a to_date with whatever date you want to test with.

For example:
LVL 74

Expert Comment

ID: 40540260
>> ora-01846 not a valid day of the week"

Monday is a valid day, the code works for any database I tried it on.  Does your database have different nls settings?

The IW method should work regardless though,  ISO weeks are defined to start on Monday and the NLS settings are irrelevant to that.

Simple test for thousands of dates

select * from
(select trunc(sysdate + rownum,'IW') d from all_objects)
where to_char(d,'Dy') != 'Mon';

if that query returns any rows then the IW didn't work, if returns 0 rows then it worked.  Of course the 'Mon' string is subject to NLS settings though, change as needed

Author Comment

ID: 40540290
Guys thankyou both for the help

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question