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.
Similar Messages
-
Function module to calculate no of days between two date ranges
hi experts,
can some one please suggest a function module that can calculate no of days between specified date range.
for example : if i enter date range between 26.02.2011 to 20.05.2011, then it should calculate no of days between these dates.
Moderator message : Basic date questions not allowed. Read forum rules before posting. Thread locked.
Edited by: Vinod Kumar on May 25, 2011 10:57 AMHi,
Please search SDN.. there are lots of posts for teh same.
[http://wiki.sdn.sap.com/wiki/display/ABAP/FunctionModulerelatedonDate+calculations] -
Calculate business day between two dates
Hi Guys
I need the count of business days between two dates
Date1, Date2 i need the count only business day (exclude sartuday&sunday)
If date1 is null or nothing i need to pass 0
If date2 is null or nothing i need to pass 0
help on thisHi,
To achive this within SSRS, go to the report code window and add the below
Function getBusinessDaysCount(ByVal tFrom As Date, ByVal tTo As Date) As Integer
Dim tCount As Integer
Dim tProcessDate As Date = tFrom
For x as Integer= 1 To DateDiff(DateInterval.Day, tFrom, tTo) + 1
If Not (tProcessDate.DayOfWeek = DayOfWeek.Saturday Or tProcessDate.DayOfWeek = DayOfWeek.Sunday) Then
tCount = tCount + 1
End If
tProcessDate = DateAdd(DateInterval.Day, 1, tProcessDate)
Next
Return tCount
End Function
In the textbox where you need to display the value, add the below expression
=Code.getBusinessDaysCount(parameters!StartDate.Value,parameters!EndDate.Value)
It is assumed the you want to pass the two days from parameters named Startdate and EndDate. If not, modify the expression with required values.
Regards
Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH -
Calculating Business Days(Start_dt - End_dt)
Hi Friends,
Could anyone of you help me to find out the business days(Excluding Saturdays and Sundays) between two dates.
The difference should be calculated of both the Start_dt and End_dt values truncated. The result should be calculated and stored according to business days, it means weekend days are to be ignored.
create table sample (id number,start_dt date,end_dt date). The table values are as follows;
ID ; start_dt ; End_dt
1 ; 08-02-2012 ; 15-02-2012
2 ; 30-12-2011 ; 15-02-2012
My output should be;
ID ; start_dt ; End_dt ; Expected Business Days (Excluding Weekends)
1 ; 08-02-2012 ; 15-02-2012 ; 4
2 ; 30-12-2011 ; 15-02-2012 ; 33
Please note that, the Start Date and End Date can be any date from any year. Please help me on this.
Regards,
Williams.
Edited by: Williams on Feb 8, 2012 6:28 PM
Edited by: Williams on Feb 8, 2012 6:29 PMHere's my first cut at it.
SQL> WITH sample AS
2 (
3 SELECT 1 AS id, TO_DATE('08-02-2012','DD-MM-YYYY') AS start_dt, TO_DATE('15-02-2012','DD-MM-YYYY') AS end_dt FROM DUAL UNION ALL
4 SELECT 2 AS id, TO_DATE('30-12-2011','DD-MM-YYYY') AS start_dt, TO_DATE('15-02-2012','DD-MM-YYYY') AS end_dt FROM DUAL
5 )
6 /* END SAMPLE DATA */
7 SELECT id
8 , start_dt
9 , end_dt
10 , COUNT(*)
11 FROM sample
12 JOIN ( /* Exclude Weekends */
13 SELECT dt
14 FROM ( /* Generate a range that includes all days */
15 SELECT min_start_dt + (LEVEL - 1) AS dt
16 , TO_CHAR
17 ( min_start_dt + (LEVEL - 1)
18 , 'fmDAY'
19 , 'NLS_DATE_LANGUAGE=AMERICAN'
20 ) AS dy
21 FROM ( SELECT MIN(start_dt) AS min_start_dt
22 , MAX(end_dt) AS max_end_dt
23 FROM sample
24 )
25 CONNECT BY LEVEL <= max_end_dt - min_start_dt + 1
26 )
27 WHERE dy NOT IN ('SATURDAY','SUNDAY')
28 ) dys ON dys.dt BETWEEN start_dt AND end_dt
29 GROUP BY id
30 , start_dt
31 , end_dt
32 /
ID START_DT END_DT COUNT(*)
2 12/30/2011 00:00:00 02/15/2012 00:00:00 34
1 02/08/2012 00:00:00 02/15/2012 00:00:00 6
2 rows selected.I got different results then you though. Can you say why your counts are what they are? -
Adding Business Days to a Date to create New Date
I am looking to add a formula to auto calculate a new date, but only want to count business Days.
Currently I am using formula to calculate how many days need to be added:
//ODD Priority Business Days
If left ({DEFECT.PRIORITY}, 1)= "1" then 10
else
If left ({DEFECT.PRIORITY}, 1)= "2" then 20
else
If left ({DEFECT.PRIORITY}, 1)= "3" then 50
else
If left ({DEFECT.PRIORITY}, 1)= "0" then 10
Now I need to create a formula to add these numbers to the date field, for conversation purposes, I need to add these business days to my "start date" to equil my "ODD date".
Example, if my "start date" is 1/1/2009 and it is a Priority 2, then I need to add 20 business days to that, so the "ODD date" would be: 1/29/2009.
Please help.Thank you Garrett Fitzgerald! Please see the modified formula which I meant
{Startdate}
+ {@BusinessDays}
- DateDiff("ww", {Startdate}, {Startdate} + {@BusinessDays}, crSaturday)
- DateDiff("ww", {Startdate}, {Startdate} + {@BusinessDays}, crSunday)
Regards,
Raghavendra -
Need Help Calculating Business Days AND omitting Holidays...
Post Author: dkotenoglou
CA Forum: Formula
Thanks to the people here I was able to get a nice formula to help me calculate the amount of business days between two days.//Crystal syntax
Local DateTimeVar d1 := ;
Local DateTimeVar d2 := ;
DateDiff ("d", d1, d2) -
DateDiff ("ww", d1, d2, crSaturday) -
DateDiff ("ww", d1, d2, crSunday) This works great. I wanted to add the ability to omit US Holidays. Now this is a straight Crystal Reports install without an SQL backend so I cannot use any formulas there.Is there a parameter? I can use to manually create a table of dates to omit? The only reason I ask is that our company was closed during the holidays so my day reports are really high. I do not mind typing a long list of days manually (12/24/2007, 12/25/2007, etc) but I need to know how to best integrate that list into the formula.Post Author: V361
CA Forum: Formula
If you have CR XI, there is another example as well, in the sample reports, look at feature examples, custom functions.rpt this code is from that example.
Function cdDateAddSkipHolidays (nWorkingDays As Number, startDateTime As DateTime) As DateTime 'the result = startDateTime + nWorkingDays + nHolidays (including weekends) 'the algorithm below also works when nWorkingDays is negative
Dim totalDays 'give a rough estimate for total days. For each 5 work days there are 7 'days. Also add in an extra 2 weekend days to account for a partial week. totalDays = Fix(nWorkingDays * 7 / 5 + 1) + 2
Dim iteratedDiff iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)
If (iteratedDiff >= nWorkingDays) Then Do While iteratedDiff >= nWorkingDays totalDays = totalDays - 1 iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays) Loop cdDateAddSkipHolidays = startDateTime + totalDays + 1 Else Do While iteratedDiff < nWorkingDays totalDays = totalDays + 1 iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays) Loop cdDateAddSkipHolidays = startDateTime + totalDays End If
End Function -
Simple date calculation: add days to a date
Hi,
I'm looking for a function module in APO that can simply add a number of days to a date.
I know I can code (date + days) but would rather a module if possible.
Thks,
WilliamI know FM /SAPAPO/MSDP_SNPHEU_DAYS_ADD is used in SNP ... but not sure it is suitable for you.
-
Adding Business Days to a Date
Hi everyone,
I'm trying to add a certain number of working days to a date,what I am hoping to get is a date excluding the weekends
For example:
If i was to add 12 working days to 01/05/2009 i should get 19/05/2009
Thank You
MTMistook 01/05/2009 as Jan 5th and was wondering why your statements contradicted. I see you mean May 1st.
Try a formula such as this:
numbervar i := 1;
datevar c := date(#05/01/2009#);
numbervar z := 12;
datetimevar k := date(0,0,0);
while i <= z do
k := dateadd('d',i,c);
(if dayofweek(k) in [1, 7] then
(z := z + 1;)
k := date(0,0,0);
i := i +1;
dateadd('d',z,c);
where 'C' is the starting date and 'Z' is the number of working days. -
Tax not calculating in MIRO within a date range.
Hi Experts ,
We have created a tax code and assign its values in condition types under two separate Key Combination.
1) Tax Classification : 4% ( Non Validity) , in access sequence exclusive indicator is set aganst it.
2) Tax Code : 4% (Valdity - Sept - till 9999), Exclusive indicator is not set against it.
Issue is that when i create a PO ( at any date) system is picking up the taxes.
Nom at the time of MIRO , if i post the MIRO before sept. system is allowing me to do so and calculate taxes correctly.
But when i change the date to Sept the system does not calculate taxes.
Even though the Tax Classification has more priority in access sequence compared to tax code , i am failed to understand why system is not calculating taxes.
I have tried deleting conditions in tax code key combinations but still system is not calculating taxes in MIRO,
Pls guide.
Regards
HoneyHi Ramesh ,
i have done the same . Maintained he condition record via FV11. but system is not calculating tax for sept. month in MIRO.
In PO tax calculation is perfect but in MIRO it is not calculating tax.( ticked calculate tax option also). -
Calculation of days base on dates
I have an input of date through 3 jcombo box captured in string denoting dd/mm/yyyy.
I need to compute the two dates entered into the system a derive the number of days.
Please advise how I could do that.import java.util.Calendar;
public long numberOfDay(int year1,int month1,int day1,int year2,int month2,int day2)
Calendar cal1=Calendar.getInstance();
cal1.set(year1,month1,day1);
Calendar cal2=Calendar.getInstance();
cal2.set(year2,month2,day2);
long ms=0;
if(cal1.before(cal2))
ms=cal2.getTime().getTime()-cal1.getTime().getTime();
else
ms=cal1.getTime().getTime()-cal2.getTime().getTime();
long s=ms/1000;
long m=s/60;
long h=m/60;
return h/24;
}You could use this, before to make your string, or change on regarding the Callendar class
JHelp -
FM to get number of working days in a date range for a calender
Hi all,
Can you tell me the Function Module which takes start date ,, end date and factory calender as input and gives back working days or number of working days as return.
Win full points for the resolution...
Thanks in Advance...
Chandan DubeyHi chandan,
1. DATE_CHECK_WORKINGDAY
This is one useful FM
2. Try this code (just copy paste)
IT DOES EXACTLY WHAT U REQUIRE.
REPORT abc.
data : num type i.
parameters : frdate type sy-datum default '20051216'.
parameters : todate type sy-datum default '20051221'.
perform getinfo using frdate todate changing num.
break-point.
*& Form getinfo
text
FORM getinfo USING fromdate todate CHANGING numofdays type i.
DATA : d TYPE sy-datum.
d = fromdate - 1.
DO.
d = d + 1.
IF d > todate.
EXIT.
endif.
CALL FUNCTION 'DATE_CHECK_WORKINGDAY'
EXPORTING
date = d
factory_calendar_id = '01'
message_type = 'I'
EXCEPTIONS
date_after_range = 1
date_before_range = 2
date_invalid = 3
date_no_workingday = 4
factory_calendar_not_found = 5
message_type_invalid = 6
OTHERS = 7.
IF sy-subrc = 0.
numofdays = numofdays + 1.
write :/ d.
ENDIF.
ENDDO.
ENDFORM. "getinfo
I hope it helps.
Regards,
Amit M. -
Calculating Average Days in Crystal Reports using a Visual FoxPro driver
Post Author: sher
CA Forum: Crystal Reports
I use the following code in a crystal XI report to calculate average days between two dates using the sql server driver. It worked fine. I used the same code in a crystal XI program using a visual FoxPro driver. It does not work. Can someone help me with code needed to calculate average days using a visual foxpro driver?
cast ( Avg( DateDiff( DD, CREDENTIALING.APPLICATION_RECEIVED, ENTITYASSIGNMENTS.STATUSASOF )) As int ) AS AvgDaysFromReceipt,
cast ( Sum( DateDiff( DD,CREDENTIALING.APPLICATION_RECEIVED, ENTITYASSIGNMENTS.STATUSASOF)) As int ) AS TotDaysFromReceiptNot 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. -
Calculation of due date based on Business Days for FICA documents
Hi All,
I am working on project where SD - FICA integration is in picture. We post some charges through SD and FICA document gets posted on relevant Contract Account.
Normally we create Sales Order using transaction VA01 and then we do Billing for this Sales Order through VF01. After billng is done, FICA document automatically gets generated.
We have following requirement to be fulfilled.
For the SD bills posted as above, I want to calculate due date of these bills based on Business Days for FICA document generated (SAP Standard calculate due date based on Calander days). We can use factory calander for calculating business days in relevant function module.
I have checked in the system and it seems that event 1330 ( FM - ISU_DUE_DATE_DETERMINE) is not working in this scenario. Is there any other FM which I can use?
Can anyone help me on this?
Regards,
PradeepHello Praeva ,
The event 1330 has a sample FM FKK_SAMPLE_1330. It doesnt even have a Standard Function Module.
You need to create a Installation-Specific FM and put your code to determine the Due Date based on the logic.
Rgds
Ram Kumar. -
Subtract business days from date - calculated column
Hello,
I had a calculated column on a library that took two dates and found the difference between them in business days, but I am not sure how to subtract business days from a date...for instance I get a start date from a form and I need to
subtract 10 business days from that date.
Can anyone help?I've always resorted to Javascript/JQuery for that kind of function. I found an old fashioned loop worked the best for me - it supports going forward or backwards. I key it off of a change in a starting date, or sometimes a status change. My actual production
code takes into account another list where we remove holidays and non-work days.
newDate = getNextDate(newDate, -3);
$("input[title='Date Due']").val((newDate.getMonth() + 1) + "/" + newDate.getDate() + "/" + newDate.getFullYear());
function getNextDate(currentDate, offset) {
// offset is business days
var wkend = 0;
var index = Math.abs(offset); // need positive number for looping
var neg = true;
if(offset >= 0) { neg = false; }
var curDOW = currentDate.getDay();
var nextDate = new Date(currentDate);
for(var i=1; i <= index; i++) {
nextDate.setDate(nextDate.getDate() + (neg ? -1: 1));
var nextDOW = nextDate.getDay();
if(nextDOW == 0) {nextDate.setDate(nextDate.getDate() + (neg ? -2: 1));} // Sunday
if(nextDOW == 6) {nextDate.setDate(nextDate.getDate() + (neg ? -1: 2)); } // Sat
// alert("offset is " + offset + "start: " + currentDate + ", next date is " + nextDate);
return nextDate;
Robin -
List all dates in date range even if there is no record for that day
Hi,
I have a really simple report but am having a problem with dates.
I want to list sales per day over a date range (start date and end date parameters).
The data i am working with may not have sales on every day which is causing grief with my average calculations.
I need to capture days in current month which i have with DateDiff ("d", {?Start Date}, {?End Date}+1)
Then days elapsed in the month. This is where my problem is. I have grouped my data by day to get day totals, and have then attempted to use a summary on DISTINCT COUNT to get the result i need. The problem is it only counts the lines that are there, so if a day has no sales it is skipped and the count is incorrect and then the average calculations i have are not correct.
Help will be much appreciated.YOu can not create data that does not exist.
You will need to add in a table which has all dates and make that you first table with all other data joined with a left out from this date table.
Ian
Maybe you are looking for
-
did something get stuck in the button?
-
I had to get a new hard drive for my macbook pro ,and unfortunatly i lost all my music ,but It is on my ipad...The problem is when I go to sync my ipad .The itunes on my computer wants to delete all the music on my ipad and replace it with the music
-
Dear all. I'm having a problem unable to send a simple e-mail to LotusNotes environment. My task is using method SENDTASKDESCRIPTION with type id "G" and the receiver is HR position id (S 99999999). The SAPconnect has been configure and schedule prop
-
Server 2012R2 Windows backup 100% CPU usage and no backup
Hello! I have a problem with two VM´s on a HP Proliant ML350p Gen8, that has Windows Server 2012R2 operating system with Hyper-V role installed. Both VM´s are also 2012R2, one is DC/DNS/FILE/PRINT and the other one is Exchange 2013. The problem itsel
-
I use the ethernet cable to connect my airport extreme to a linksys router to extend the network but suddenly all the ethernet cables on airport extreme stopped working and now the linksys won't get a connection. I was wondering why this might of hap