Author Topic: Date Question  (Read 7353 times)

jaxmudd

  • Newbie
  • *
  • Posts: 1
    • View Profile
Date Question
« on: February 14, 2011, 09:02:13 AM »
Hello, In Oracle I am looking for the most efficent way to say...If today is monday give me Friday-Sunday, if it is not Monday give me the previous days date. I have seen something close in a where clause with a case but I just can't get the syntax correct.

Thanks in advance


Mike

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
    • View Profile
Re: Date Question
« Reply #1 on: February 15, 2011, 08:39:42 PM »
Can you explain a little more clearly what it is that you're trying to achieve?

Also, do you want SQL or PL/SQL?

Hello, In Oracle I am looking for the most efficent way to say...If today is monday give me Friday-Sunday, if it is not Monday give me the previous days date. I have seen something close in a where clause with a case but I just can't get the syntax correct.

Thanks in advance

Prakash

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Date Question
« Reply #2 on: October 04, 2013, 02:04:41 PM »
/* Formatted on 10/4/2013 4:02:34 PM (QP5 v5.240.12305.39476) */
SELECT CASE
          WHEN TO_CHAR (TO_DATE (SYSDATE, 'dd/mm/yyyy'), 'DAY') = 'MONDAY'
          THEN
             SYSDATE + 4
          WHEN TO_CHAR (TO_DATE (SYSDATE, 'dd/mm/yyyy'), 'DAY') <> 'MONDAY'
          THEN
             SYSDATE - 1
       END
          expected_date
  FROM DUAL;