Breaking a year in coming weeks of beginning and end Dates (parameters) and first and last day of the month
Hello people:
I have currently a query that picks up all the weeks between a date range where my week starts on Thursday and ends on Wednesday. The following query works fine except that I need the week of beginning and end, from beginning and end Dates of months and the beginning and the Dates of end of the values of the settings, I'm passing. In this case, I chose January 1, 2013 to 31 December 2013.
Any help or pointers would be great!
Thank you!
Problem: I am picking up days of December 2012 as the first week began on December 27, 2012. In addition, in December, I'm pretty much lost last week as well (26 December - 31 December).
The request in hand:
SELECT first_thursday + (7 * (LEVEL - 1)) AS week_start_date, first_thursday + (7 * LEVEL) - 1 AS week_end_date FROM ( SELECT TRUNC(p_from_date + 4, 'IW') - 4 AS first_thursday, -- Week should start the pre ceeding THURSDAY based on the Start Date TRUNC( p_to_date + 4, 'IW') - 5 AS last_wednesday FROM ( SELECT to_date('01-JAN-2013') AS p_from_date, NVL(to_date('31-DEC-2013'), SYSDATE) AS p_to_date FROM dual ) parms ) end_points CONNECT BY LEVEL <= ( last_wednesday + 1 - first_thursday)/7;
Currently, this is the result I get (I'm only including the months of January and December here).
Week_Start_Date Week_End_Date 27-DEC-12 02-JAN-13 03-JAN-13 09-JAN-13 10-JAN-13 16-JAN-13 17-JAN-13 23-JAN-13 24-JAN-13 30-JAN-13 31-JAN-13 06-FEB-13
December:
28-NOV-13 04-DEC-13 05-DEC-13 11-DEC-13 12-DEC-13 18-DEC-13 19-DEC-13 25-DEC-13
What I would really like is based on start and end Dates, as well as the first and the last day of the month is similarly try nicely. I have provided and then gently break at the end of the month:
January:
01-JAN-13 02-JAN-13 03-JAN-13 09-JAN-13 10-JAN-13 16-JAN-13 17-JAN-13 23-JAN-13 24-JAN-13 30-JAN-13 31-JAN-13 31-JAN-13
February:
01-FEB-13 06-FEB-13 07-FEB-13 13-FEB-13 14-FEB-13 20-FEB-13 21-FEB-13 27-FEB-13 28-FEB-13 28-FEB-13
November:
31-OCT-13 06-NOV-13 07-NOV-13 13-NOV-13 14-NOV-13 20-NOV-13 21-NOV-13 27-NOV-13 28-NOV-13 04-DEC-13
December:
01-DEC-13 04-DEC-13 05-DEC-13 11-DEC-13 12-DEC-13 18-DEC-13 19-DEC-13 25-DEC-13 26-DEC-13 31-DEC-13
Hello
Roxyrollers wrote:
Hello people:
I have currently a query that picks up all the weeks between a date range where my week starts on Thursday and ends on Wednesday. The following query works fine except that I need the week of beginning and end, from beginning and end Dates of months and the beginning and the Dates of end of the values of the settings, I'm passing. In this case, I chose January 1, 2013 to 31 December 2013.
Any help or pointers would be great!
Thank you!
Problem: I am picking up days of December 2012 as the first week began on December 27, 2012. In addition, in December, I'm pretty much lost last week as well (26 December - 31 December).
The request in hand:
- First_thursday SELECT + (7 * (LEVEL - 1)) AS week_start_date,
- first_thursday + (7 * LEVEL)-1 AS week_end_date
- Of
- (
- SELECT TRUNC (p_from_date + 4, 'IW') - 4 AS first_thursday,-week should start to perform the pre-mounted THURSDAY based on the Start Date
- TRUNC (p_to_date + 4, 'IW') - 5 AS last_wednesday
- Of
- (
- SELECT to_date('01-JAN-2013') AS p_from_date,
- NVL (to_date('31-Dec-2013'), SYSDATE) AS p_to_date
- OF the double
- ) parms
- ) end_points
- CONNECT BY LEVEL<= (="" last_wednesday="" +="" 1="" -="">=>
Currently, this is the result I get (I'm only including the months of January and December here).
- Week_Start_Date Week_End_Date
- DECEMBER 27, 12 2 JANUARY 13
- JANUARY 3, 13 JANUARY 9, 13
- 10 JANUARY 13 JANUARY 16, 13
- 17 JANUARY 13 23 JANUARY 13
- 24 JANUARY 13 30 JANUARY 13
- 31 JANUARY 13 FEBRUARY 6, 13
December:
- NOVEMBER 28, 13 4 DECEMBER 13
- 5 DECEMBER 13 DECEMBER 11, 13
- 12 DECEMBER 13 18 DECEMBER 13
- 19 DECEMBER 13 DECEMBER 25, 13
What I would really like is based on start and end Dates, as well as the first and the last day of the month is similarly try nicely. I have provided and then gently break at the end of the month:
January:
- JANUARY 1, 13 2 JANUARY 13
- JANUARY 3, 13 JANUARY 9, 13
- 10 JANUARY 13 JANUARY 16, 13
- 17 JANUARY 13 23 JANUARY 13
- 24 JANUARY 13 30 JANUARY 13
- 31 JANUARY 13 JANUARY 31, 13
February:
- 1ST FEBRUARY 13 FEBRUARY 6, 13
- 7 FEBRUARY 13 FEBRUARY 13, 13
- 14 FEBRUARY 13 FEBRUARY 20, 13
- 21 FEBRUARY 13 FEBRUARY 27, 13
- 28 FEBRUARY 13 FEBRUARY 28, 13
November:
- 31 OCTOBER 13 NOVEMBER 6, 13
- 7 NOVEMBER 13 NOVEMBER 13, 13
- 14 NOVEMBER 13 NOVEMBER 20, 13
- 21 NOVEMBER 13 NOVEMBER 27, 13
- NOVEMBER 28, 13 4 DECEMBER 13
December:
- 1ST DECEMBER 13 DECEMBER 4, 13
- 5 DECEMBER 13 DECEMBER 11, 13
- 12 DECEMBER 13 18 DECEMBER 13
- 19 DECEMBER 13 DECEMBER 25, 13
- 26 DECEMBER 13 DECEMBER 31, 13
Why the "weeks" in November, have all 7 days, while the "weeks" in the first or the last week in the other month usually have less? (For example, February 28 is a 'week' alone.)
The following works for the other months:
WITH all_days AS
(
SELECT DATE "2013-01-01' + LEVEL - AS a_date 1
OF the double
CONNECT BY LEVEL<=>=>
)
SELECT DISTINCT
More GRAND (TRUNC (a_date + 4, 'IW') - 4)
, TRUNC (a_date, 'MONTH')
) AS week_begin
, The LEAST (TRUNC (a_date + 4, 'IW') + 2
TRUNC (LAST_DAY (a_date))
), Week_end
Of all_days
ORDER BY week_begin
;
Output:
WEEK_BEGIN WEEK_END
----------- -----------
January 1, 2013 January 2, 2013
January 3, 2013 January 9, 2013
January 10, 2013 January 16, 2013
January 17, 2013 January 23, 2013
January 24, 2013 January 30, 2013
January 31, 2013 January 31, 2013
February 1, 2013 February 6, 2013
February 7, 2013 February 13, 2013
February 14, 2013 February 20, 2013
February 21, 2013 February 27, 2013
February 28, 2013 February 28, 2013
...
November 1, 2013 November 6, 2013
November 7, 2013 November 13, 2013
November 14, 2013 November 20, 2013
November 21, 2013 November 27, 2013
November 28, 2013 November 30, 2013
December 1, 2013 December 4, 2013
December 5, 2013 December 11, 2013
December 12, 2013 December 18, 2013
December 19, 2013 December 25, 2013
26 December 2013 31 December 2013
Tags: Database
Similar Questions
-
Select SQL - last day of the month, a year from now
Hello
How do we get the last day of the month, a year from now.
For example-sysdate-12/2/2009
Result - 31/12/2009
Thank youHello
SELECT LAST_DAY ( ADD_MONTHS ( SYSDATE , 12 ) ) FROM dual;
Remember, all DATEs, including the results of this query, include the hours minutes and seconds.
The hours, the minutes and the seconds returned by the above expression are the same as SYSDATE: If you run it at 15:43:30 today, it returns 15:43:30 on December 31, 2010. This can be important if you want to use an expression like this as the cut-off point in a WHERE clause. -
get the first and last day of the year
and razm.date > = to_date ("' 1.01 ' |: $VDATE |", ' dd.mm.yyyy ") AND razm.date < = to_date ('31.12.2010. ' || (": $VDATE |", ' dd.mm.yyyy ");
but I get:
ORA-01830: date format picture ends before converting all of the input string
01830 00000 - "date format picture ends before converting all of the input string.
* Cause:
* Action:
: $VDATE is entered as 2010 param. I need to get data from range 1.1.2001 to 31.12.2010
THXWhy don't you use:
to_char(razm.date,'YYYY') = :VDATE
-
How to find the first day of the month following two years one year from now?
Hello
I need to find the first day of the month following two years ago, based on the current date.
For example: If today is the 31/08/2015 so I need to find the date range between 31/08/2015 and on 09/01/2013. How can I write an SQL which allows to automate this calculation instead of hard-coding the values. Please do help me out with this so that I can build the SQL that can produce the desired result.
Thank you
Dhilip
find the start of the month - 2 years in advance, early - 2 years + 1 months in advance and go back 1
Select trunc (add_months(sysdate,24), 'MM'), trunc (add_months(sysdate,25), 'MM') - 1 double;
-
Last day of the year in fast formula
Hi all
I have to deal with something special, based on the last day of the current year.
How can I get the last day of the year? Is there a function available in the fast formulas?
Appreciate all entries...
Thank you
SRSWhat is
:
L_last_day = TO_DATE (' 31 - DEC-'+ TO_CHAR (PAY_PROC_PERIOD_END_DATE, 'YYYY'), 'DD-MON-YYYY')
:Clive
-
How to get the last day of the week?
HII
I can get the week number of calendar for a given date using
SELECT to_char (to_date('04/04/2011','MM/DD/YYYY'), 'WW') FROM dual
can any body tell me, how to get the last day of the week?
and the answer should be: 04/08/2011(8th april)
Thank you
San
Published by: sandeep9 on April 4, 2011 03:50Perhaps this...
SQL> select trunc(sysdate,'WW')+6 from dual; TRUNC(SYSDATE,'WW')+ -------------------- 08-APR-2011 00:00:00 SQL>
-
How to get the last day of the year
Hi all
Thanks in advance...
How do I get the last day of the year that I'm passing date at run time.
I can manage to get the first day of the year by
SELECT TRUNC(SYSDATE,'YEAR') AS FDAY_YEAR
of the double
Thanks in advance
Concerning
Sachin1* select ADD_MONTHS(trunc(sysdate,'yyyy'),12)-1 dd from dual SQL> / DD ----------- 31-DEC-2010
-
How do the 3rd week (business day) of the month in a date range?
Hello
I'm trying to find the 3rd day of the work week of each month in a given range of dates. How is it possible in a SQL query? Thank you in advance.
Hello
Here's one way:
SELECT first_day + BOX
WHEN TO_CHAR (first_day, "DY") IN ("play", "Fri", "SAT")
THEN 4
WHEN TO_CHAR (first_day, "DY") ("SUN")
THEN 3
2 ELSE
END AS workday_3
DE)
SELECT ADD_MONTHS (first_month
, LEVEL - 1
) AS first_day
DE)
SELECT TO_DATE ('Sep 2013', 'My YYYY') AS first_month
, TO_DATE ('Jan 2014', 'Mon YYYY') AS last_month
OF the double
)
CONNECT BY LEVEL<= 1="" +="" months_between="" (last_month,="">=>
)
ORDER BY workday_3
;
In another thread,.
https://community.Oracle.com/thread/3513808
you said that you had problems using a WITH clause, so I used online views instead of CLAUSES.
With the above parameters, the result is:
WORKDAY_3
---------------
Wed 04-Sep-2013
Set of 3 October 2013
November 5, 2013 Mar
Wednesday, December 4, 2013
Fri January 3, 2014
-
Hello
Can someone help me with the problem I am facing to... my scenario is currently that we show reports from 00 hours up to 24 hours. But now the client wants to exact more than 24 hours for chart reports.
This means that if the time is now 16:05 hours, then graphical report must display data for 16:00 Hrs from yesterday until 16:00 hours that day. Is the same for the last week day 24 hours as well. Means they need two lines in the chart. Please help me...
Thank you
Srini VIEREN Terry.Williams dileraco
Hello
Now using these variables filter your column of measure...
Kind regards
Naga
-
Find first &; last day of the week of the given date
Hi all
I have the input query, below
I would like to get output that is below start date week (Saturday) & the end of the week (Friday)
DT Period of the WEEK Max Date in this week Min Date this week June 16, 12 WEEK 24-2012 June 16, 12 22 June 12 July 4, 12 WEEK 27-2012 30 June 12 July 6, 12 January 4, 13 WEEK 01-2013 January 4, 13 29 December 12 January 7, 13 WEEK 02-2013 5 January 13 January 11, 13 January 8, 13 WEEK 02-2013 5 January 13 January 11, 13 January 9, 13 WEEK 02-2013 5 January 13 January 11, 13 January 10, 13 WEEK 02-2013 5 January 13 January 11, 13 January 11, 13 WEEK 02-2013 5 January 13 January 11, 13 June 4, 13 WEEK 23-2013 1 June 13 June 7, 13 Indicate also if a function available in oracle for this one.
Like this? I think in your required output, 3rd line data, MAX_DATE should be 29 December 12 and MIN_DATE should be January 4, 13.
WITH TEM AS
(SELECT 11 January 13 ' DT double Union)
SELECT 16 June 12 ' Union double
SELECT 4 July 12 ' Union double
SELECT January 9, 13 ' Union double
SELECT 10 January 13 ' Union double
SELECT 4 January 13 ' Union double
SELECT January 7, 13 ' Union double
SELECT 4 June 13 ' Union double
SELECT 8 January 13 ' double)
SELECT D1 DT,
WK WEEK_PERIOD,
BOX WHEN (TRIM (TO_CHAR (D1, 'DAY')) = 'SATURDAY') THEN D1
ANOTHER NEXT_DAY(D1,'SATURDAY')-7
END AS MAX_DATE_IN_THIS_WEEK,
BOX WHEN (TRIM (TO_CHAR (D1, 'DAY')) = 'FRIDAY') THEN D1
OF OTHER NEXT_DAY(D1,'FRIDAY') END AS MIN_DATE_IN_THIS_WEEK
DE)
SELECT TO_DATE (DT) D1,' WEEK ' | To_char (to_date (DT), 'IW-YYYY') tem WK)
ORDER BY DT;
OUTPUT:
DT WEEK_PERIOD MAX_DATE_ MIN_DATE_
--------- ------------ --------- ---------
JUNE 16, 12 WEEK 24-2012 16 JUNE 12 22 JUNE 12
4 JULY 12 WEEK 27-2012 JUNE 30, 12 6 JULY 12
4 JANUARY 13 WEEK 01-2013 29 DECEMBER 12 JANUARY 4, 13
JANUARY 7, 13 WEEK 02-2013, JANUARY 5, 13 JANUARY 11, 13
JANUARY 8, 13 WEEK 02-2013, JANUARY 5, 13 JANUARY 11, 13
JANUARY 9, 13 WEEK 02-2013, JANUARY 5, 13 JANUARY 11, 13
10 JANUARY 13 WEEK 02-2013, JANUARY 5, 13 JANUARY 11, 13
JANUARY 11, 13 WEEK 02-2013, JANUARY 5, 13 JANUARY 11, 13
4 JUNE 13 WEEK 23-2013, JUNE 1, 13 JUNE 7, 13
9 selected lines.
-
Hi friends,
I have the below query that returns me the data as below:
Select 'Label', to_number (to_char (to_date(start_date,'yyyy-mm-dd'), 'IW')) - to_number (to_char (add_months (sysdate,-6), 'IW')) + 1 as a weekly sum, (col1) val yyy_view
where to_date(start_dt,'yyyy-mm-dd') between trunc (add_months(sysdate,-6)) and trunc (sysdate)
Group of to_char (to_date(start_date,'yyyy-mm-dd'), 'IW')
order of to_char (to_date(start_date,'yyyy-mm-dd'), 'IW')
Label weekly val
1 20 data
2 24 data
3 20 data
4 28 data
5 20 data
6 24 data
and so on...
Now the requirement is to get the last date of the week for each week as below
Label weekly val
given 2011-08-30 20
given 2011-08-23 24
given 2011-08-16 20
given 28 2011-08-09
given 2011-08-02 20
the weekly column should have the date of the last week. In the example above Wednesday is supposed to be the last date of the week.
Kind regards
PradeepMissed the part "Wednesday is considered date of last week. The week is Thursday to Wednesday. If so:
select 'Label', trunc(min(start_dt)) as day2, sum(col1 ) val from yyy_view where start_dt between trunc(add_months(sysdate,-6)) and trunc(sysdate) group by trunc(start_date - 3,'IW') order by trunc(start_date - 3,'IW') /
SY.
-
Start the computer in normal mode, tried to download Microsoft Security Essentials, during download of Mozilla rediredted.
Then restarted and I tried to download the malware Microsoft Windows (KB890830) removal tool, tried twice and was redirected each time.
Any suggestions?
Hi JudiDue,
· What browser do you use?
· You did it all change hardware or software on your machine before this problem?
If you are using internet Explorer, you can follow this link & check if the problem persists.
How to restore a hijacked web browser
Reference: what is the browser hijacking?Hope the helps of information.
Please post back and we do know.
-
How to get the Date in month based on week of the month.
Hi gurus,
I have provided.
Quarter (Q) = > 1 (Jan - Mar), 2 (April-June), 3 (July-September), 4 (October-December).
Months (M) = > Jan = 1, Feb = 2, Mar = 3 in the 1st quarter.
ARP = 1, may = 2, Jun = 3 in the 2nd quarter,
Jul = 1, August = 2, Ms = 3 in Q3,
Oct 1 Nov = = 2, Dec = 3 in the 4th quarter
If I give Q = 3, M = 3, W = 1 day = Fri so I get 6-Sep-13
Similarly, if I give Q = 2, M = 1, O = 3, day = game so I get 18 April 13.
Could someone help me higher and higher.
Concerning
Sanjeev
Believing that when you say you want to say that it is 1 - 5 in a month with the 1st day of the month as the beginning of the 1st week of the week. You can try this.
SQL > t
2 as
(3)
4. Select q 3, 3 m, 1 w, 'Ven' d
5 double
6 union
7 all the
8. Select q 2, 1 m, 3 w, d 'game '.
9 double
10)
11. Select q, m, w, d, d_day
12 years of)
13 select y + (level - 1) d_day
14, ceil (extract (day of cast (y + (level - 1) as timestamp)) / 7) week_7_day
15 , t.*
16 of)
17 select add_months (trunc (sysdate, 'year') (q * 3-3) +(m-1)) y
18 , t.*
19 t
20 ) t
21 connect
22 by level<= last_day(y)="" -="" y="" +="">=>
23 and prior y = y
dbms_random.value (24 and prior) is not null
25 )
where the 26 w = week_7_day
27 and substr (to_char (d_day 'day'), 1, 3) = lower (d);Q M W D D_DAY
---------- ---------- ---------- --- ---------
2 1 3 Friday 18 April 13
3 3 1 Fri 06-SEP-13SQL >
-
by selecting specific days of the week for the date range?
I have a table with a number of clients for about a year, but I want to only select Wednesday and Thursday of
every week, since the beginning of the dates. Table is simple and has two columns. Each line is separate from a Date
There is no duplicate of Date, it is counted for every day of the year.
column 1: number of clients, count (customer_id)
column 2: Date
Need help with the best way to achieve this.
Not sure if it is even possible to select a date in the name of the day?
Basically, I want to select every Wednesday and Thursday of each week and compare the counts during the week, the week during
week for the whole week see if charges go upwards or downwards, to get trends, thank you!Hello
Kodiak_Seattle wrote:
I have a table with a number of clients for about a year, but I want to only select Wednesday and Thursday of
every week, since the beginning of the dates. Table is simple and has two columns. Each line is separate from a Date
There is no duplicate of Date, it is counted for every day of the year.column 1: number of clients, count (customer_id)
column 2: DateNeed help with the best way to achieve this.
Not sure if it is even possible to select a date in the name of the day?
Sorry, we don't know what you want.
To see if a date given (dt) is a Wednesday or Thursday, you can use:
WHERE TO_CHAR ( dt , 'DY' , 'NLS_DATE_LANGUAGE=ENGLISH' -- If necessary ) IN ('WED', 'THU')
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002} -
How to calculate this column (the last week of the month)?
I have a request where it shows a few months of calculations of sage
ex. This report is for Dec-2010
statement line. A reduced rate. Approved rate. Last week declined the rate |
-------------------------
Asia report | ------20%----- | -----45%-------- | --------4%------ |
Africa report | ------44% -----| -----21%-------- | ------12%-------|
I'm figuring the column rate declined last week . The logic is simply not coming to my mind.
Can someone suggest me how can I calculate this?We'll see. This report at any time after the previous month running has closed...
(1) TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE) will give you the last day of the previous month.
(2) TIMESTAMPADD (SQL_TSI_DAY, DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) *-1, TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) will give you the Saturday before the last week of the month.
(3) TIMESTAMPADD (SQL_TSI_DAY, 1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE)) *-1, TIMESTAMPADD (SQL_TSI_DAY, (DayOfMonth (CURRENT_DATE)) *-1, CURRENT_DATE))) will give you the Sunday of the last week of the previous month.
Now that you have the start of the last day of the previous week, you can create your filter... It will be "(between 3) and 1)" above... "
Maybe you are looking for
-
How can I move an e-mail in my Inbox in one of my folders on a Mac?
at the same time I could click on "move" and select the name of the folder, but this option does not appear.
-
Laptop won't turn on, flashing lights
Hello My laptop is a HP Pavilion dv6z-1100 sound running a 64 bit version of windows 7 Home premium, and recently, he stopped at boot the system successfully. While being used, all of a sudden the screen went dead (without warning) and the computer t
-
Pavilion 7000: Computer freeze once the fan CPU runs at max speed
Product name: Pavilion 7000 Product model: 7 p - 1090d Product no.: QP177AA #UUF Operating system: Windows 7 Home Premium 64 - bit version. Computer blocks once the fan CPU runs at max speed. Initially, the computer would occationally freeze after wa
-
m8120n Pavilion Media Center: can not enter audio speakers
Hi, I just bought a set of speakers Creative Inspire T5400 2.1 which have 3 sons. I plugged in the audio, but I get no sound. The three shots that I plug are marked side rear c/sub. The speaker is marked simularly. The volume mixer is marked device,
-
Hi all Please help me more. I have created several BitmapFields and put them in HorizontalFieldManager. But these BitmapFields are always left aligned. I want to be focused on these fields. How can I do this? Examples? Thank you DK.