No of Fridays in between two date
Hi all
What is the Qucikest and easy way to retreive the NO of fridyas in betwen two dates
Thanks & Regards
Vivek
vivekvm wrote:
Hi all
What is the Qucikest and easy way to retreive the NO of fridyas in betwen two dates
Make sure you test the boundary conditions for any solution you get.
Have you defined exactly what you mean by "in between two dates", for example. do you want to count the end points if one, or both, of them is a friday ?
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
"Science is more than a body of knowledge; it is a way of thinking"
Carl Sagan
Similar Messages
-
How to count the number of Fridays and Saturdays between two dates
Hi every one ... If we want to count the number of Fridays and Saturdays between two dates, how would we do that ? !
Dates are ( 11-Feb-2010) to (19-May-2010)
how to do it in SQL
Edited by: khalidoracleit on Jul 28, 2010 5:51 AMsome nice coding here, I'm still amazed with what some people can do with "connect by". But I agree with some statements here that this can take "time", and to be honest, it's funny to see it working, but if you do not have a computer, just a calendar and some paper, would you go for "counting" so there must be a better solution?
The best working math in here is done by Aketi Jyuuzou, who writes so good English that I wonder why he still insists that he doesn't ;-)
Anyhow I "translated" that code to English, and I really like that math. Math is math and data is data.
ALTER SESSION SET NLS_DATE_LANGUAGE='ENGLISH';
WITH my_dates AS (
SELECT to_date('20100211','yyyymmdd') start_date,to_date('20100519','yyyymmdd') end_date FROM DUAL
UNION ALL
SELECT to_date('20100211','yyyymmdd') start_date,to_date('20100214','yyyymmdd') end_date FROM DUAL
UNION ALL
SELECT to_date('20100211','yyyymmdd') start_date,to_date('20100213','yyyymmdd') end_date FROM DUAL
UNION ALL
SELECT to_date('20100211','yyyymmdd') start_date,to_date('20100212','yyyymmdd') end_date FROM DUAL
SELECT to_char(start_date,'DD.MM.YYYY') start_date,to_char(end_date,'DD.MM.YYYY') end_date,
to_char(start_date,'DAY') start_weekday,to_char(end_date,'DAY') end_weekday,
end_date-start_date day_difference,
(next_day(end_date,'FRIDAY')-7
-next_day(start_date -1,'FRIDAY'))/7+1
+(next_day(end_date,'SATURDAY')-7
-next_day(start_date -1,'SATURDAY'))/7+1 as count_of_fr_and_sat
FROM my_dates;
START_DATE END_DATE START_WEEKDAY END_WEEKDAY DAY_DIFFERENCE COUNT_OF_FR_AND_SAT
11.02.2010 19.05.2010 THURSDAY WEDNESDAY 97 28
11.02.2010 14.02.2010 THURSDAY SUNDAY 3 2
11.02.2010 13.02.2010 THURSDAY SATURDAY 2 2
11.02.2010 12.02.2010 THURSDAY FRIDAY 1 1 -- andy -
Working days between two date fields and Changing Factory Calendar
Hi,
I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
I have written the routine using factory calender and its working fine except for two problems now:
1. If any one of the date field is empty then teh rsult should be zero.
2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
I am new to ABAP. Please help me how i can achieve these for below code.
DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
IS_HOLIDAYS TYPE ISCAL_DAY.
DATA: T_DATE TYPE SY-DATUM,
P_DATE TYPE SY-DATUM.
DATA : X_DATE(4) TYPE C.
DATA: CNT TYPE I.
REFRESH : IT_HOLIDAYS.
CLEAR : IT_HOLIDAYS.
T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
CALL FUNCTION 'HOLIDAY_GET'
EXPORTING
HOLIDAY_CALENDAR = 'CH'
FACTORY_CALENDAR = 'CH'
DATE_FROM = P_DATE
DATE_TO = T_DATE
TABLES
HOLIDAYS = IT_HOLIDAYS
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 1
HOLIDAY_CALENDAR_NOT_FOUND = 2
DATE_HAS_INVALID_FORMAT = 3
DATE_INCONSISTENCY = 4
OTHERS = 5.
DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
X_DATE = T_DATE - P_DATE - CNT.
RESULT = X_DATE.
Please help
Regards
Zabina
Edited by: Syed786 on Nov 2, 2011 9:15 AMHi Zabina,
Try this function module 'DURATION_DETERMINE'.
Give the factory calendar and unit as DAY
With regards,
Rajesh -
How to calculate the month difference between two date char. in Query?
Customers would like to see how many months passed between two date type of characteristics (e.g., the month difference between the current date and the scheduled delivery date in the record) and put the result into the column as KF.
We would have to grab the fiscal year/period kind of value and then do the subtraction, e.g., if the current date value is 2/28/2008 and the scheduled delivery date value in the record is 12/01/2007, the correct result should be 2 month difference between these two date values, but could someone here give us the technical light on how to make this happen in query design?
Thanks and we will give you reward points for the correct anwsers!Hi Kevin,
The Badi is RSR_OLAP_BADI.
You can create an implementation using Transaction SE18.
The implementation is per cube and is defined in the filters.
In the Implementation you have the following methods :
1. Define : Here you will provide the Keyfigure you need as a virtual one.
2. Initilialize : Any Init Function you want to do.
3. Compute. This is called per datarecord and here you can cimpute your value.
Hope this helps.
Pralay Ahluwalia -
As to the data type of the data type of the difference between two date type of datas
Hi,
I have a question about the data type of the difference between two date type of datas.
There are two date type of datas as:
SSHIPMENTS.RECEIVEDATETIME
SSHIPMENTS.PROMISEDATETIME
I try to use the following SQL Script in Oracle SQL*Plus as:
SELECT CASE
WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:00:00.000' THEN 'OnTime'
WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:30:00.000' THEN '60-89 Minutes'
ELSE '3+ Hours'
END
FROM SSHIPMENTS;
The error message of "Invalid Number" for the '000 01:30:00.000' happens.
I don't know if the data type of the interval is wrong.
Many Thanks,
CathySELECT CASE
WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss')) < '010000' THEN 'OnTime'
WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss'))< '000 01:30:00.000' THEN '60-89 Minutes'
ELSE '3+ Hours'
END
FROM SSHIPMENTS;
just try it out.. -
How can i get report between two dates?
Hi
how can i get report between two dates?
for example i want get reports between 20/4/2002 & 27/4/2002.
my table has date column and i can get first date( exam : .... where date:=a and/or ....i don't know this part)
thanks alot.
Regards
The Oracle Reports Team
http://otn.oracle.com/where exam_date between :from_date and :to_date
from_date and to_date are user_parameter -
Difference between two date ,according to office time.
hi,
How can I get diffrence between two date.
If I select from-date 20-03-2012 09:30AM and to-date 20-03-2012 06:30PM then output should be 1 day(as it is office time from 09:30 AM TO 06:30 PM).
ACCORDINGLY If I select from-date 20-03-2012 09:30AM and to-date 21-03-2012 02:00PM then output should be 1.5 day
select 24*(to_date(:P2_TO_DATE,'DD-MM-YYYY HH:MIPM') - to_date(:P2_FROM_DATE,'DD-MM-YYYY HH:MIPM'))"date" from dual;Hello Shirish,
WITH dates AS(
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('20-03-2012 06:30PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('20-03-2012 04:15PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 12:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('22-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('22-03-2012 10:00AM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
,times as(
SELECT start_date
,end_date
,TRUNC (end_date - start_date) days
,MOD (end_date - start_date,1) hours
,(start_date - 9.5/24 - TRUNC (start_date))*24 offset_start
,(end_date - 9.5/24 - TRUNC (end_date))*24 offset_end
,(end_date - 9.5/24 - TRUNC (end_date))*24
- (start_date - 9.5/24 - TRUNC (start_date))*24 offset_diff
FROM dates
SELECT TO_CHAR(start_date, 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_CHAR(end_date, 'DD-MM-YYYY HH:MIPM') AS end_date
,days
,ROUND(offset_start,2) offset_start
,ROUND(offset_end,2) offset_end
,ROUND(offset_diff,2) offset_diff
,CASE WHEN offset_diff > 4 THEN
days + 1
WHEN offset_diff > 0 THEN
days + 0.5
WHEN offset_diff = 0 THEN
days
WHEN offset_diff + 9 > 4 THEN
days + 1
ELSE
days + 0.5
END computed_days
FROM timesThe first step (subquery times) computes the full days and the difference between start_date and end_date, compared to the beginning of the office ours (9.5 /24)
The second step takes the days and according to the possible values of the difference adds a half or a full day.
Regards
Marcus
Edited by: Marwim on 19.03.2012 11:23
CASE offset_diff = 0 -
Date difference between two dates
hi All,
i have to right a stored proc to find the difference between two dates.
for example of i give
startdate as 4/1/2015 and enddate 14/1/2015
i should get 1 year , 10 days and 0 months .
i have tried the DateDiff function but it does not calculate the leap year.
please help.DECLARE @from datetime
DECLARE @to datetime
SET @from = '20150104 8:00'
SET @to = '20150114 10:30'
SELECT DATEDIFF(minute,@from, @to) % 60 as Minutes
SELECT (DATEDIFF(minute,@from, @to) / 60) % 24 as Hours
SELECT DATEDIFF(minute,@from, @to) / (60 * 24) as Days
SELECT DATEDIFF(month,@from, @to) as Months
SELECT DATEDIFF(year,@from, @to) as Year
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Difference between two date in bex query
Hi all,
I need to do a difference between two date using formula variable processing type customer exit beaucause I must use factory calendar in the formula.
How can I do it?
Can you give me an example of the routine?
Thanks a lot
GianmarcoHi,
You can still use the same code to copy it and customize as per your need. All you need to do is to subract the dates using the class: CL_ABAP_TSTMP after converting to timestamp and resulting seconds you convert back to days....Please get help from the developers to do this...
Also, ensure that you write back this difference value to your variable so you get it on the reports for your calculations...
Cheers,
Emmanuel. -
Find the difference between two dates for the specific month and year
Hi,
I have two dates, start date is 30/12/2012 and end date is 04/01/2013. Using datediff I found the difference of days between two dates. But I find the no of days in January 2013. ie output is 4 instead of 6. I input month and year to find the no of days
for that date. In this case I input Jan 2013. How can I sql this ?I don't understand how most of the answers provided here not analytically solving the problem with many cases possible.
First let me understand you:
You have 2 dates range and you want to calculate day range for specific month and year between the original date range.
declare @for_month int = 1 --January
declare @for_year int = 2013
declare @StartDate date = '2012-12-20'
declare @EndDate date = '2013-01-04'
SELECT
CASE
WHEN (DATEPART(MONTH, @StartDate) = @for_month and DATEPART(MONTH, @EndDate) = @for_month) and ((DATEPART(YEAR, @StartDate) = @for_year or DATEPART(YEAR, @EndDate) = @for_year)) THEN
DATEDIFF(DAY, @StartDate,@EndDate)
WHEN (@StartDate < cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (@EndDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, DATEADD(MONTH, DATEDIFF(MONTH, -1, @EndDate)-1, 0),@EndDate)
WHEN (@EndDate > cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) and (@StartDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, @StartDate,DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @StartDate) + 1, 0))) + 1
WHEN ((DATEDIFF(DAY, @StartDate, cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) >= 0) and (DATEDIFF(DAY, cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date), @EndDate) >= 0)) THEN
DATEDIFF(DAY, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime), DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime)) + 1, 0))) + 1
ELSE
0
END as [DD]
I don't know how you calculate day range between 01/01/2013 and 04/01/2013
is 4, it is actually is 3 but if that is the case, you can add 1 from the condition. -
Select Query Between two dates...
Hi Guru's,
I need a Select Query between two dates, also if the record not found for any in between date then it should return NULL or 0 ...
for Example
1. I am having two records in DB for date 2-10-2008 & 4-10-2008
2. Now suppose I have given Query for date between 1-10-2008 to 5-10-2008
Then it should return me 5 records with valid values for 2 & 4 and NULL for other 1,3,5
Thanks.Try like this:
with
t as
select date '2008-10-02' as dt, 'Record #1 (in DB)' as str from dual union all
select date '2008-10-04' as dt, 'Record #2 (in DB)' as str from dual
select v.dt, t.str
from (
select date '2008-10-01' + level - 1 as dt
from dual
connect by level <= (date '2008-10-05' - date '2008-10-01') + 1
) v
left join t
on v.dt = t.dt
order by 1 -
Using pl/sql function for each day between two dates.
Hi,
create TABLE EMP(
ID_EMP NUMBER,
DT_FROM DATE,
DT_TO DATE,
CREATE_DATE DATE);
into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
I have a function called elig_pay_dates(date p_date), which returns the code for person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
By using this function with select I needs to display the dates when there is a change in status.
I am expecting data in following manner from above logic(this is example):
07/01/2008 --- 07/01/2009 ---'P'
07/02/2009 -- 07/25/2009 ----'N'
07/26/2009 -- 01/01/2010 ---'P'
01/02/2010 -- 01/13/2010 --'N'
01/14/2010 -- 01/18/2010 --'P'
01/19/2010 -- 04/30/2010 -- 'N'
I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
Thanks for your help,Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
create or replace
function test_ret_paid_unpaid (p_date in date)
return varchar2
is
v_ret varchar2(1);
begin
if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
(p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
(p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
then v_ret := 'N';
else
v_ret := 'Y';
end if;
return v_ret;
end;
Wrote file afiedt.buf
1 with get_paid_unpaid as
2 (
3 select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
4 row_number() over (order by dt_from + level - 1) rn_start,
5 row_number() over (order by dt_from + level - 1 desc) rn_end
6 from test_emp
7 connect by level <= dt_to - dt_from + 1
8 ),
9 get_stop_date as
10 (
11 select start_date init_date, end_date, curr_date, paid_unpaid,
12 case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
13 then curr_date
14 else null
15 end start_date,
16 case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
17 then curr_date
18 else null
19 end stop_date
20 from get_paid_unpaid
21 )
22 select period, paid_unpaid
23 from (
24 select init_date, curr_date, start_date, end_date, stop_date,
25 case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
26 then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
27 else null
28 end period,
29 paid_unpaid
30 from get_stop_date
31 where stop_date is not null or start_date is not null
32 )
33* where period is not null
12:06:10 SQL> /
PERIOD PAID_UNPAID
01-JUL-08 - 01-JUL-09 Y
02-JUL-09 - 25-JUL-09 N
26-JUL-09 - 01-JAN-10 Y
02-JAN-10 - 13-JAN-10 N
14-JAN-10 - 18-JAN-10 Y
19-JAN-10 - 30-APR-10 N
6 rows selected.
Elapsed: 00:00:00.35 -
How to Calculate second between two dates?
I'm wish to create a ref ID using seconds between two dates as the uniue number. I usually use DateDiff function in VB to calculate the ref ID. But now instead developing using VB, i'm using java in developing my project. I wonder is there any class similar to the datediff function? Please advice.Thank you
diff_sec =( Date1.getSeconds() - Date2.getSeconds());
-
Periods between two dates .
Hi,
can anyone tell me any function module dat returns the no of periods between two dates .like
if i enter 02.02.2007
05.05.2007
then it shud return periods .
011
012
001
002
003
thnx ,
point will b assigned.Hi Nishu,
I think what you are looking for in the example below is periods 02, 03,04,05 when you enter dates 02.02.2007 to 05.05.2007.
you have to write a customer exit on posting period.
check the paper below on how to write customer exit and how to derive a variable from another variable.
https://websmp210.sap-ag.de/~sapdownload/011000358700002762582003E/HowToDeriveVariableValue.pdf
Jaya -
Determine posting to an asset between two dates
Hello all,
How do you calculate the postings made to an asset between two dates? I looked at the logical database ADA, but got lost in the source code.
For example, if these posting were made to an asset between start & end date, the total I would want would be $300.
Post $200
post $100
post $200
reserse the 2nd $200.
Thanks
BruceDear Friend,
Its very easy, simply execute transaction SQV and follow the below steps
Quick Viewer Screen appers
Create a new quick view
Give it a name, data source as table join, press enter.
Press Shift+F1, put the table name ANEK and press enter
Again press Shift+F1, put the table name as ANEP this time.
Press F3 or back button
Explode the Documnet Header and select List Filed and Selection Field check box for 1. Company Code 2. Main Asset Number, 3. Asset Sub Number,4. Fiscal Year, 5. Sequence Nuber, 6. Document Date or any other date on the basis of which you want to check the postings (e.g. posting date, entery date, asset valud date etc).
Press Execute button and enter.
A Report selection will appear, put the company code other parameters you have with you inclduing the date and execute again.
This will give you all posting between particular date.
Hope this solve your issue.
Thanks!!!
Murlidhar Khatri
Maybe you are looking for
-
Can two people use the same Nike plus and Nano?
Or will we each need our own. My husband purchased one and I would also like to use it. We work out at different times and it would be nice not to have to purchase different units, but will it upload both or our workout information or does anyone kno
-
My mirroring icon is no longer showing up on my iPad. Where did it go?
Where did the mirroring icon go on my iPad? I can't find it.
-
Problem in importing XML Data In Acrobat - X
Hello All, I have a LiveCycle form where I am embedding a sample XML into it. (No data connection and no binding). After filling the form when the user clicks the submit button before submitting the XML it removes all the nodes of the sample XML that
-
Hello experts! I am trying to pass value between two pages without page submit. I set item value from first page to session state by dynamic action. Then I am trying to pass this value to second page, I use button which redirects to second page and s
-
Bringing Flash .swf files into Captivate
Greetings, I use Captivate 2.0. I have been trying to bring a Flash .swf file into Captivate with very little success. The flash file is clickable (so that users can review case study information as they complete Try It simulations). When I bring the