Date range sunday to monday
Hello experts;
I would like to design a date range query where the beginning of the week is always sunday and the end of the week is always monday. All help is appreciated.
Thank you
What do you mean by "design a date range"? And " beginning of the week is always sunday and the end of the week is always monday" doesn't make much sense. If it starts Sunday then last day of the week is Saturday. Anyway, nearest Sunday is:
TRUNC(your_date_column + 1,'IW') - 1SY.
Similar Messages
-
Showing average data summarized 'Date type' (Sunday, Monday, etc.) wise
Greetings Everyone,
I'm trying to create a chart that shows data averages summarized date type wise.
Background and the specific requirement is as follows:
The application from which I fetch data is a visitor management system. User is prompted to select a date range and I want to show how many visitors have visited the office, in a day type (Sunday, Monday, etc.) breakdown.
For instance, if the date range includes four Mondays and the total number of visitors that have visited on Mondays for this period is 120, then the average for Monday would be 30. Likewise, I want to summarize data for all the seven days of a week.
I have tried different cross-tab options but haven't succeeded yet,
Help would be much appreciated.
Best Regards,
Lakshan.hi Lakshan,
the answer depends on whether or not your data is missing any dates...i.e. if you've got a Monday that doesn't actually show up in your report (but is still within the date range), do you still count that? if so, that makes things a bit more difficult. if this is the case then let us know.
if your data has no gaps, then here's what you can do:
1) create a new formula called DaysOfWeek with syntax like
weekdayname(dayofweek({your date field}))
2) Insert a Chart and for the On Change Of use the DaysOfWeek formula
3) click on the formula in the On Change Of and press the Order button...use a Specified Order and add all of the week day names in by the order that you want
4) add your visitors field to the Show Value and Set the Summary Operation to Average
cheers,
jamie -
To get monday dates in a given date range
Hi,
when a give a date range from Apr 1 to Apr 30 , the query should return all the monday dates from Apr 1 to Apr 30
I.e
Apr 4
Apr 11
Apr 18
Apr 25
Please suggest me how to achieve this.Here's one way...
SQL> ed
Wrote file afiedt.buf
1 with t as (select date '2011-04-01' as start_date, date '2011-04-30' end_date from dual)
2 --
3 -- end of test data
4 --
5 select dt
6 from (
7 select start_date+rownum-1 dt
8 from t
9 connect by rownum <= (end_date-start_date)+1
10 )
11* where to_char(dt,'fmDay') = 'Monday'
SQL> /
DT
04-APR-2011 00:00:00
11-APR-2011 00:00:00
18-APR-2011 00:00:00
25-APR-2011 00:00:00
SQL> -
Group by week between date range
Hi,
i'm having a table for documents. The documents are received from diffeent dates. I've to calculate number of documents received on weekly basis.
I need an sql to count the number of documents between two given dates grouping by weekly.
My week starts on Sunday and ends with Saturday.
I've tried group by with to_char(documentdate,'IW') , but this will take Monday to Sunday as a week & the incomlete weeks i'm not able to calculate. ie : in the below output the date range 1/28/2007 - 1/31/2007 is not a complete week . ( ie saturday to wednesday)
I need out put should be like this for Date Range: 12/31/2006 to 1/31/2007
week count of documents
12/31/2006 - 1/6/2007 10
1/7/2007 - 1/13/2007 40
1/14/2007 - 1/20/2007 30
1/21/2007 - 1/27/2007 20
1/28/2007 - 1/31/2007 10
Please help me to get this.....
(columns in documents table is documentid and documentdate)your're very close with IW. you just need to shift the data to get it to fall within the correct range. btw, you don't need julian dates. it's overkill
trunc(date+1,'IW') will push the date into the correct week range (IW will put sunday one week earlier than you want, so push it ahead a day before truncating).
then subtract 1 day from the result to get it to display with sunday's date instead of monday
trunc(mydate+1, 'IW')-1
and the week end date is simply trunc(mydate+1, 'IW')_5
select mydate, to_char(mydate,'Dy') dy,
trunc(mydate+1,'IW')-1 wk_Start,
trunc(mydate+1,'IW')+5 wk_end
from (select sysdate-rownum mydate from dual connect by level < 20)
order by 1 -
Function Module which will take Wekk No & Return date range (from & To dat)
Hello everyone,
I need a Function Module which will take Week No as an input Parameter & return me the date range
(From date & To date of that week) .
Thanks in advance!
Cheers!
Moderator message: date calculation questions = FAQ, please search before posting.
Edited by: Thomas Zloch on Nov 2, 2010 5:25 PMHi,
Please write the below logic..
data : v_date11 type sy-datum,
monday type sy-datum,
sunday type sy-datum,
v_count1 type i .
*v_count1 = 20 * 7. " Say U want details for 20th week , or give a parameter for week and multiply with 7*
v_date11 = '20100101'. " take the starting day of the year ....
v_date11 = v_date11 + v_count1. " add to the date
CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE' <-- call this FM
EXPORTING
DATE = v_date11
IMPORTING
WEEK = WEEK
MONDAY = MONDAY <-- will have the week starting day
SUNDAY = SUNDAY
Regards,
Srini. -
Hi,
There is a requirement that we need to get date range.This date range will be arrived at using the function module BKK_GET_PRIOR_WORKDAY. The factory calender id is GB. It should return the date range. Therefore, for weekends the date range will be Saturday, Sunday and Monday. The date range will change based on holidays that exist in the holiday calendar.
Now my question is how to calculate that there are two days between friday and monday.
Please help.Hi Nishigandha,
If i am correct you need the number of days between two dates
ex:
date1: 04/06/2009
date2: 12/06/2009
you need the number of days??
then probably check this Fm out:
SD_DATETIME_DIFFERENCE this is a function module which gives the difference in Days and Time for entered two dates
P.S Additionally Chk this out:
/people/mustafabaris.gunes/blog/2009/03/16/calculating-number-of-working-days-in-query-level
Hope its useful
Thanks and Regards
Srikanth.P
Edited by: SRIKANTH P on Jun 4, 2009 2:33 PM -
If I give 27 th week of 2007, can I get date range ( any FM is there ?)
In my selection screen I am giving 27 th week and year 2007,
I need to know know the date range ( monday to sunday ) for that week .
For eg. if I give <b>1st</b> week and year <b>2007</b>,
It should display 01/01/2007 to 07/01/2007 ( like DD/MM/YYYY ).
is there any function module available to know this ?Hi sam ,
just execute the code by giving date and see if this works for u ,,
check with input as 01/01/2007 i hope this will do ..
parameters : P_DATE LIKE SCAL-DATE.
DATA : HDATE LIKE SY-DATUM,
LDATE LIKE SY-DATUM.
data: WEEKno LIKE SCAL-WEEK,
refmonDAY LIKE SY-DATUM,
REFSUNDAY LIKE SY-DATUM.
CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
EXPORTING
DATE = p_date
IMPORTING
WEEK = weekno
MONDAY = refmonday
SUNDAY = refsunday.
write:/ 'weeknumber', weekno,
write:/ 'monday' ,refmonday.
write:/ 'sunday', refsunday.
see if this works for u ..
can you can tell me ur input criteria as how u r passing the date if u r query is not completed ..
regards,
vijay -
Hi,
I want a count of def as well as starting day of the week based on FDate week wise.
I have build a case structure starting from beginning to end of the week. But it is not working.
Please let me know a way where i can get a count of def for each week as well as starting day of the week.
For the WHERE clause i have a given a date range but it should be for the last 20 weeks.
SELECT FDate, count(def)
from Table
WHERE FDate > = '2008-03-17' and FDate <= '2008-08-07'
group by FDate
order by
case when FDate >= '2008-03-17' and FDate <= '2008-03-23' Then '2008-03-17'
when FDate >= '2008-03-24' and FDate <= '2008-03-30' Then '2008-03-24'
when --------
when --------
end
Please help.
Thanks.Hi,
While you could use a 20-pronged CASE statement, it's much eachier to use
GROUP BY TRUNC (fdate, 'IW')
TRUNC (fdate, 'IW') returns the DATE of the last Monday (12 midnight) that was on or before fdate. ("IW" stands for Iinternational Standards Organization Week.) It's an easy way to map an entire week into one value, and, unlike the 'D' format that Kevin and Guido mentioned earlier, it works the same regardless of you NLS settings.
What if you need to combine things by week, but you want to consider Sunday the start of the week? That's 1 day earlier than the ISO Week, and instead of
TRUNC (fdate, 'IW') you would use
TRUNC (fdate + 1, 'IW') - 1. -
Any FM to get count of each week day for the given date range
Hi guys,
Any FM to get count of each week day for the given date range?
eg: If i give 14/07/2008 to 14/08/2008
I need to find how many Mondays, tuesdays...sundays in this given date range.
If not single FM is available, any logic that gives above result is also appreciated.
Thanks,
Vinod.hi Vinod,
this is not a full solution, I just give you a basic idea:
DATA : lv_start TYPE sy-datum VALUE '20080714',
lv_end TYPE sy-datum VALUE '20080814'.
WHILE lv_start LE lv_end.
CALL FUNCTION 'FTR_DAY_GET_TEXT'
EXPORTING
pi_date = lv_start.
* IMPORTING
* PE_DAY_TEXT1 =
* PE_DAY_TEXT2 =
* PE_DAY =
* you have to summarize the output here somehow...
lv_start = lv_start + 1.
ENDWHILE.
hope this helps
ec -
How to change a date to sunday prior to any date
Hi All,
I have a requirement to change a date to sunday prior to any date. for example,
If date is 6/30/08 , then i need to change it to 6/29/08. If date is 6/26/08, then i need to change it to 6/22/08.
How to do the same.
Regards,
NehaHi ,
i think u can use this FM
GET_WEEK_INFO_BASED_ON_DATE
Import parameters Value
DATE 26.06.2008
Export parameters Value
WEEK 200826
MONDAY 23.06.2008
SUNDAY 29.06.2008
by using this FM u will get Starting date of that week will come , in this case 23/06, so u need to code like this
last sunday = mmonday - 1.
regards
Prabhu -
Count # weeks in a date range...how?
Greetings:
I've a sql statement to find me the begining & ending dates for a date range that must begin on Sunday and end on a Saturday.
SELECT (NEXT_DAY(TO_DATE(p_start_dt, 'MM/DD/YYYY'), 'SATURDAY')) - 6,
(NEXT_DAY(TO_DATE(p_end_dt, 'MM/DD/YYYY'), 'SATURDAY'))
INTO v_Begining_Week_Dt, v_Ending_Week_Dt
FROM DUAL;
Question: With these two dates, how can one determine how many weeks there are within this date range? (I'm looking for a number type return value.)
Thanks in advance for any and all guidance.
With best regards,
Ed in TampaOkay...I didn't realize that by substacting the dates will give me a number type. I'm good to go now.
-
Calculated Date Range in Lookup Column
I want to have a lookup column on a list called Report Week. The report week is a date range between Sun and Sat. I could easily make a column of ranges in a seperate list and then use it as a lookup but I am hoping for something more
elegant. What I envision is the user selecting the Date Range lookup in a list item and the date ranges shown are the previous, current and upcoming weeks. So the dropdown list would look like this:
09/20/14 - 09/26/14
09/27/14 - 10/03/14
10/04/14 - 10/10/14
Can this be done w/out using .NET? Thanks in advance.more or less, you need three calculated columns (well, you may be able to do it in just the one, but it'll be obnoxious to write the formulas)...
- start date
=> DateAdd([date field], 0 - (dayofweek([datefield]))
basically, subtract the day of week from the reference date... this should give you the sunday that starts the week
- end date
=> DateAdd([date field], 7 - (dayofweek([datefield]))
basically the same, except this adds the remaining number of days in the week, to give you the saturday that ends the week
- range (description)
=> concatenate([start date], " - ", [end date])
you may need to fiddle with the formulas a little bit... run them in excel to tweak them.
Scott Brickey
MCTS, MCPD, MCITP
www.sbrickey.com
Strategic Data Systems - for all your SharePoint needs -
Workday calculation for specified date range
Hi All,
How to count number of workdays available for given date range. And I tried below statement which is
not working.
SUM(CASE [Calendar].[Calendar Date]
WHEN [Calendar].[Calendar Date].[Year] = '2005' AND [Calendar].[Calendar Date].[Month]
= 1
THEN [Calendar].[Calendar Date].CURRENTMEMBER.CHILDREN
END
, [Measures].[Work Day Flag])Hi bpbhhaskar,
According to your description, you want to count the weekdays in MDX. Right?
In this scenario, we can just aggregation days from Monday to Friday. The key should be 2 to 6. Please use the expression below:
with
MEMBER [Measures].[DayCount] AS
Count
Descendants
[Date].[Calender].CurrentMember
,[Date].[Calender].[Date]
* {[Date].[Day Of Week].&[2]:[Date].[Day Of Week].&[6]}
Best Regards,
Simon Hou
TechNet Community Support -
Calculating Business Days in a Date Range
I have two questions:
1. Does anyone know a better formula for calculating business days in totals?
I am currently using the formula in https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/701a52c3-6b1e-2b10-21b3-a6e101be1a0f
I tailored to my needs. However, there are still a lot of manual maintenance every year.
2. I have many reports that need the formula. It is very consuming to update the formula in each report. Does anyone know a better way to do it?
I use Crystal XI. 11.0.0.895. We do have a Crystal Enterprise server hosted in another department.Not sure if this is any simpler but you could save this as a custom function, that way you will have to modify it once a year for the holidays.
numbervar days;
datevar date1 := minimum({?My Parameter});
datevar date2 := maximum({?My Parameter});
days := DateDiff ("d", date1, date2) -
DateDiff ("ww", date1, date2, crSaturday) -
DateDiff ("ww", date1, date2, crSunday); // this will give you the number of business days
// (excluding Saturdays and Sundays) for a given date range.
// then, for each holiday, you can enter lines like this
if date(2008,01,01) in {?My Parameter} then days := days - 1;
// The final tally of DAYS should give you the total business days in a date range.
totext(days,0);
where {?My Parameter} is the date range. -
Grouping totals by date ranges
Hi All,
I have an ASP.NET application, in which I have to get totals from a table using different criteria, which I do like this:
SELECT DISTINCT
SUM(CASE WHEN MYCONDITION1 THEN 1 ELSE 0 END) AS TOTAL1,
SUM(CASE WHEN MYCONDITION2 THEN 1 ELSE 0 END) AS TOTAL2
FROM TABLE1, TABLE2
WHERE COMMON_CONDITION1 AND COMMON_CONDITION2
AND BETWEEN DATE1 AND DATE2;
This works fine and I get the intended result.
Now, I have to repeat this for every week for the last 12 months, excluding holidays period. So, I generate a set of date ranges which will be used in the queries. So, I repeat the above sql statement for all the date ranges, which is a lengthy process.
I have to get the totals for every week. For example from 26-Sep-2010 to 02-Oct-2010, 19-Sep-2010 to 25-Sep-2010, 12-Sep-2010 to 18-Sep-2010, etc.. How should I put those ranges in the group by and select statement, because, I don't have them in a table.
How can I do that in a single shot and get all totals for each date range. Please help me with sql.
Thank you.
Edited by: 800729 on Oct 7, 2010 4:33 AMHi,
Welcome to the forum!
800729 wrote:
Hi All,
I have an ASP.NET application, in which I have to get totals from a table using different criteria, which I do like this:
SELECT DISTINCT
SUM(CASE WHEN MYCONDITION1 THEN 1 ELSE 0 END) AS TOTAL1,
SUM(CASE WHEN MYCONDITION2 THEN 1 ELSE 0 END) AS TOTAL2
FROM TABLE1, TABLE2
WHERE COMMON_CONDITION1 AND COMMON_CONDITION2
AND BETWEEN DATE1 AND DATE2;Does that really work? Don't you have to do something like
AND date_column BETWEEN DATE1 AND DATE2Post actual code, simplified if necessary, but still something that you can run.
This works fine and I get the intended result.
Now, I have to repeat this for every week for the last 12 months, excluding holidays period. So, I generate a set of date ranges which will be used in the queries. So, I repeat the above sql statement for all the date ranges, which is a lengthy process.
I have to get the totals for every week. For example from 26-Sep-2010 to 02-Oct-2010, 19-Sep-2010 to 25-Sep-2010, 12-Sep-2010 to 18-Sep-2010, etc.. How should I put those ranges in the group by and select statement, because, I don't have them in a table.Are you saying your current query produces 1 row, but you want something that has 53 rows, one for each week in the last year?
If so, add a "GROUP BY x" clause, as Sabnkar suggested, where x is a distinct value for each week.
You will probably *not" want to use TO_CHAR (date_column, 'WW'), especially if all of the output is not in the same calendar year.
If your weeks always begin on Sunday, then TRUNC (date_column, 'D') would be a better GROUP BY exptression, but it depeneds on your NLS settings.
GROUP BY TRUNC (date_column + 1, 'IW') - 1 will do the same thing, regardless of your NLS settings.
You may not need a table tha has one row per week, but if you do, Sauhik showed you how to generate a result set that will work just as well.
How can I do that in a single shot and get all totals for each date range. Please help me with sql.I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data, as Saubhik requested.
Include examples of holidays: it's very unclear how you want to handle them. What is a "holday period"? How do you know if a given date is in one or not?
Simplify the problem as much as possible. For example, post a problem that gets the last 3 weeks, instead of the last 53 weeks. Anyone who suggests a solution will show you how to change it for 53 weeks, if necessary.
Maybe you are looking for
-
ORA-01017 error while using a database link
Hi all, I have a TNS entry as below HOME= (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=10.66.205.110)(PORT=1521)) (CONNECT_DATA=(SID=HOME)) I have created a database link as create public database link link92.com using 'HOME'. This was created successf
-
Using a java project in a web which is part of a ear
hi i have an ear (jspkeepEAR) that includes a web project (jspkeep). The web project uses a java project (common). I don't want the EAR to know about the common, so i've added the common as a j2ee module to the web project. when publishing, i can see
-
Function modules in a function group
Hi hoe many function modules can a function group contain and can we create a function module with out import parameters.
-
How can you block a URL from access?
This URl (http://reduled.info/3131) keeps coming up as mal in Avast. Can a specific URL be blocked?
-
Exception handling when no execuble bindings available in PageDefinition?
Currently I'm showcasing a simple authentication example to one of our clients. The example consists of the following : * a simple AuthenticationFilter setup in my web.xml * a simple (V1 ... not V2) DataAction with a modelReference property pointing