Cameron
Cameron

Reputation: 7

Oracle conversion from SQL Server - WeekRange Based on Date

I need help converting some SQL Server code to Oracle.

This relates to selecting the week range based on a date.

SQL Server Example

select 
    (CONVERT(Varchar(8)
    , (dateadd(dd,(datediff(dd,0,getdate())/7)*7,0)), 1)) + ' - ' +                                         
    (CONVERT(Varchar(8)
    , (dateadd(dd,((datediff(dd,0,getdate())/7)*7)+6,0)), 1))   WeekRange

Results

WeekRange = 09/14/20 - 09/20/20

Today's Actual Date

09/18/20

Upvotes: 0

Views: 28

Answers (1)

Littlefoot
Littlefoot

Reputation: 143113

That would be something like this:

SQL> select to_char(trunc(sysdate, 'iw')    , 'mm/dd/yy') || ' - ' ||
  2         to_char(trunc(sysdate, 'iw') + 6, 'mm/dd/yy') result
  3  from dual;

RESULT
-------------------
09/14/20 - 09/20/20

SQL>

Upvotes: 3

Related Questions