Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get first and last day of week in Oracle?

Tags:

sql

oracle

I need to get the first day and the last day of the week from some strings that have the format like this:

'201118'

where 2011 is the year and 18 is the number of the week. Knowing the number of the week, how do I get the first and the last day of the week?

How do I do this?

like image 865
Alex Avatar asked Apr 01 '11 15:04

Alex


People also ask

How to find first day of the week in Oracle?

Add the number of weeks which is the difference between the last obtained date's week number and the specified week number, and that will yield the last day of the desired week. Subtract 6 days to obtain the first day.

What is IW in Oracle?

The 'WW' function returns the week number based on 1-7 days (one being the first week of the year). Therefore the first seven days of the year will be regarded as the first week. There is another function named 'IW', which is based on a Saturday to Sunday days format. For example, January 6, 1998 is a Tuesday.

What is Trunc in Oracle?

The TRUNC (number) function returns n1 truncated to n2 decimal places. If n2 is omitted, then n1 is truncated to 0 places. n2 can be negative to truncate (make zero) n2 digits left of the decimal point.

How do you print all dates of particular month in a table in Oracle?

Here's what I got to work: SELECT TRUNC(SYSDATE, 'MM') + LEVEL - 1 AS day FROM dual CONNECT BY TRUNC(TRUNC(SYSDATE, 'MM') + LEVEL - 1, 'MM') = TRUNC(SYSDATE, 'MM') ; The key in this query is TRUNC(SYSDATE, 'MONTH') which is the first day of the current month.


1 Answers

WEEK

select TRUNC(sysdate, 'iw') AS iso_week_start_date,
       TRUNC(sysdate, 'iw') + 7 - 1/86400 AS iso_week_end_date
from dual;

MONTH

select 
TRUNC (sysdate, 'mm') AS month_start_date,
LAST_DAY (TRUNC (sysdate, 'mm')) + 1 - 1/86400 AS month_end_date
from dual;
like image 189
user3378814 Avatar answered Oct 18 '22 20:10

user3378814