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
MT
Mistook 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.
Similar Messages
-
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 -
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. -
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 -
Adding 1 day to a date in BPEL
Hi,
Im trying to add 1 day to a date in a BPEL proces. I saw that there was a xp20:add-dayTimeDuration-to-dateTime so I tried using this in several ways. I didnt expect the input variable to be a string. I tried converting my date to a string and adding 1 day like this:
xp20:add-dayTimeDuration-to-dateTime(xp20:format-dateTime(string(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum')), 'YYYY-MM-DD'), 'P1D')
But the variables which I try to fill stays empty. The element which I try to fill is of type dateTime. Is this maybe the error that add-dayTimeDuration-to-dateTime returns a string and it cannot cast it to dateTime?
Can anyone tell me how to solve this properly?
Thanks in advance!Hi,
I refactored my expression to look like this:
xp20:format-dateTime(xp20:add-dayTimeDuration-to-dateTime(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum'), 'P1D'), '[Y]-[M]-[D]')
But the I receive an error: XMLElement cannot be cast to java.lang.String
Then I tried:
xp20:format-dateTime(string(xp20:add-dayTimeDuration-to-dateTime(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum')), 'P1D'), '[Y]-[M]-[D]')
Because xp20:add-dayTimeDuration-to-dateTime needs a String as input and I dont know how getVariableData returned it but with this I get the error:Parse Error in string function
Any ideas? -
Adding 30 days to a date in a dynamic LC form
Hello-
I'm working on a dymnamica form that is merged with XML data. In the XML, I get a FirstQuoteDate and bind it to the corresponding field in the form. I then have to calculate the ValidDate by adding 30 days to the FirstQuoteDate and display that date int he Valid Date field.
I've tried several scripts with no luck. Below is the latest script I tried. I also tried the script in several different events. I believe it is the calculate event for the ValidDate field right now. Does anyone know what I am doing wrong?
var QuoteDt = Date2Num(PROPOSAL.Page2Summary.FirstQuoteDate.rawValue, "MM/DD/YY")
var FutureDt = QuoteDt+30
var ValidDt = Num2Date(FutureDt, "MM/DD/YY")
PROPOSAL.Page2Summary.ValidDate.rawValue = ValidDtWhat event should I be putting this script in? Am I thinking I can't put it in the Change event because the date isn't being entered through the form so the field never actually changes? Do I have to use a different event? The FirstQuoteDate and ValidDates are actually floating text fields in my form. I did find that example out there from a different discussion and have tried this script in the initialize event of the First QuoteDate field and it didn't work for me.
ValidDate.rawValue = Num2Date(Date2Num(xfa.event.newText, "M/D/YYYY")+30,"MM/DD/YYYY"); -
Adding Business Days to a formula
All-
The formula below is adding a certain number of days to a call date based on dialer result code, but I want to be able to exclude Saturdays and Sundays.... And if it's not too much trouble holidays when adding the days.
My formula is called @Workdate:
If {DIALER_IVRCALLDETAIL.IVRDISPID}=106 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3
else
if {DIALER_IVRCALLDETAIL.IVRDISPID}=105 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3
else
if {DIALER_IVRCALLDETAIL.IVRDISPID}=90 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+2
else
if {DIALER_IVRCALLDETAIL.IVRDISPID}=91 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3
Else
if {DIALER_IVRCALLDETAIL.IVRDISPID}=92 then {DIALER_IVRCALLDETAIL.CALLSTARTDT}+2
I would appreciate any help you can offer!
Thanks!
JamesLets name the existing formula like this
@DateCalculated:
If {DIALER_IVRCALLDETAIL.IVRDISPID} in [106,105,91] then ({DIALER_IVRCALLDETAIL.CALLSTARTDT}+3
- DateDiff("ww", {DIALER_IVRCALLDETAIL.CALLSTARTDT}, {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3, crSaturday)
- DateDiff("ww", {DIALER_IVRCALLDETAIL.CALLSTARTDT}, {DIALER_IVRCALLDETAIL.CALLSTARTDT}+3, crSunday))
else
if {DIALER_IVRCALLDETAIL.IVRDISPID} in [90,92] then ({DIALER_IVRCALLDETAIL.CALLSTARTDT}+2
- DateDiff("ww", {DIALER_IVRCALLDETAIL.CALLSTARTDT}, {DIALER_IVRCALLDETAIL.CALLSTARTDT}+2, crSaturday)
- DateDiff("ww", {DIALER_IVRCALLDETAIL.CALLSTARTDT}, {DIALER_IVRCALLDETAIL.CALLSTARTDT}+2, crSunday))
Now create new formula like this
if weekday(@DateCalculated)=7 then
(@DateCalculated)+2
else if weekday(@DateCalculated)=1 then
(@DateCalculated)+1
else
(@DateCalculated)
place this in the report which gives the expected date.
Regards,
Raghavendra -
Subtracting/adding Business days
Hi everyone !
I have a calendar question: I have a date, number of days (either business or calendar) and Before/After indicator.
I need to calculate the future/past date depending on business/calendar nn days.
Ideally, I will also read Holidays table to fix the result with Holidays.
Any suggestions ?
CF allows me to know a weekday, add/subtract units from dates, compare dates, but nothing in the direction I mentioned...
Any suggestions will be greatly appreciated !
Gary.Make it very easy on yourself: set up a database table with date as the primary-key, then fill it with 200 years' worth of dates. ("When you run out, dig me up and I'll fix it then ...") You can put any sort of information you want to in there, such as (for example...) a "business-day number" that's used only to calculate these differences. It can literally be anything-and-everything you need to know about dates at your place of business.
When you do this, not only are "complicated calculations" eliminated at-a-stroke, but you can very easily change anything at will. You're simply using an inner-join and ... voila ... the answer is there.
Although setting up a script (in whatever language) to populate the table is a bit tedious, you only need to do it once. To me, it beats every other approach hands-down. -
Adding hours/day to a date
Hello,
I have field of length 20 which contains date in the format mm/dd/yyyy hh:mm:ss.
I want to add 5 hrs, 8 hrs, 2 days to this date value depending upon some condition.
Can anyone please suggest how to do this or any FM which does this.
Thanks in advanceHi..
DATA : FA(20) TYPE c,
FB(10) TYPE c,
FC TYPE d,
FD(8) TYPE c,
FE TYPE t.
data : f_m(10) type c,
f_d(10) type c,
f_y(10) type c,
f_h(10) type c,
f_mi(10) type c,
f_s(10) type c,
f_aa(10) type c,
f_bb(10) type c.
FA = '07/01/2007 08:09:10'.
SPLIT fa AT space INTO f_aa f_bb.
SPLIT f_aa AT '/' INTO f_m f_d f_y.
SPLIT f_bb AT ':' INTO f_h f_mi f_s.
add your logic...
i want to help you.
regards.. -
Req for FM for adding some days to sy-date
Hi experts,
my requirement is I have some 'X' number of days to finish my work.
And I need to add these number of working days (let me say 10 days )to the system date.
sy-date + 10 gives me the weekend days also.
so I need to skip the weekend days.
Do u guys have any FM or any logic to perform my task.
Thanks in advance,
Sudha........Please do a search before posting.
FM BKK_ADD_WORKINGDAY (despite the name it also does subtraction). -
Adding 1 day to a date of format YYYYMMDD format and it is char.
HI,
I have a column checktodate which is declared as char(8) and it is of format YYYYMMDD.
some of the values in the checktodate column are null and blank also.
I have to give a condition as
checktodate+1>= sysdate.
I am giving as
TO_CHAR(to_date(nvl(CHECKTODATE,0),'yyyymmdd')+1,'yyyymmdd') >= TO_CHAR(SYSDATE ,'YYYYMMDD')
I am getting the error as
ORA-01840: input value not long enough for date format
01840. 00000 - "input value not long enough for date format"
*Cause:
*Action:
kindly suggest.
Thank you.
Regards
Chaitanya.I gave the below conditions like this
select xyz,asdf,
(CASE WHEN TO_DATE(checktodate,'YYYYMMDD')+1 >= SYSDATE
THEN CHECKTODATE
ELSE TO_CHAR(SYSDATE ,'YYYYMMDD')
END) startdate
FROM dummy
where checktodate IS NOT NULL
AND INSTR(CHECKTODATE,' ') = 0
I am getting the following error
ORA-01839: date not valid for month specified
01839. 00000 - "date not valid for month specified"
*Cause:
*Action: -
Add number of business days to date field
Hello, I noticed that there is not much discussion in the forum surrounding u201Cbusiness daysu201D so I hope this post/discussion/solution contributes to the content of this forum.
I am using the following 3 formulas to try to Add number of business days (based upon a table field) to a specified date:
1. Variable name = SetVar
//Set Variable for Add Business Days:
DateVar Array Holidays;
DateVar Target:= CDate({TMS_MOVEMENT_EVT.EVT_DATE}); // Put your field name in here
NumberVar Add:= {DTCI_DOD_TRANS.TRANS}; // put the number of days here to add (a positive number)
NumberVar Added := (0);
2. Variable name = AddBizDays
//Adding Business Days:
EvaluateAfter({@SetVar});
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target
3. Variable name = HOLIDAYS
//Holiday Array Formula for the report Header:
BeforeReadingRecords;
DateVar Array Holidays := [
Date (2003,12,25), // you can put in as many lines for holidays as you want.
Date (2003,12,31)
0
I am successfully getting my data needed to make the necessary calculations and variable assignmentsu2026 I believe that my ISSUE is that I am not sure where to place these formulas into my report so they assign the variables and execute properly when previewing my report. I am curious if that is my issue, and if so, can someone provide me direction on where to put each of these formulas in my report.
Currently, when I try to preview the report, I get the following Crystal Reports Error: -u201CA number, currency amount, Boolean, date, time, date-time, or string is expected here.u201D
Then Crystal automatically opens the AddBizDays formula and highlights the word added, see below RE: u201CWHILE Addedu201D
For reference, my report has 3 groups, and I am displaying all of my output information (and locating my formulas) in the group footer #3 report section. I have moved them around to other report sections/groups/placements, but to no success.
Thanks so much.
Best, MattI worked this out... FYI - for the benefit of all forum users:
ADDING BUSINESS DAYS TO A CERTAIN DATE (excluding weekends and holidays)
1. Variable name = AddBizDays
//Adding Business Days:
WhileReadingRecords;
DateVar Array Holidays;
DateVar Target:= CDate(); // Put your field name in here
NumberVar Add:= ; // put the number of days here to add (a positive number)
NumberVar Added := (0);
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target
2. Variable name = HOLIDAYS
//Holiday Array Formula for the report Header:
BeforeReadingRecords;
DateVar Array Holidays := [
Date (2003,12,25), // you can put in as many lines for holidays as you want.
Date (2003,12,31)
0
...too bad i don't get forum points for sharing this solution.
Special thanks to KenHamady.com -- for sharing this solution.
Sincerely,
Matt -
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 -
Oracle 8i: Business Days Calculation in a Subquery
To Whom It May Concern:
I apologize if this has been posted already, but I didn't find any threads that address my issue:
I need to find the number of business days between 2 dates (excludes weekends) provided by dates from an outer query such as the following:
SELECT
C.CUSTOMER_ID
, C.ENTRY_DATE
, C.COMPLETION_DATE
, <SOME SUBQUERY HERE THAT CALCULATES THE NUMBER OF BUSINESS DAYS BETWEEN C.COMPLETION_DATE AND C.ENTRY_DATE> AS BUSINESS_DAYS
FROM CUST_TABLE C
Thanks for your time and advice.
Maxyou don't need a subquery. it's a very simple formula
Re: query regarding dates
(you may need to change the case to a decode for v8 - I don't remember when it was introduced) -
Fucntion to Calculate business days (exclude weekends & holidays) between two days
Hello,
I need to be able to calculate business days between two dates excluding weekends and holidays. I do have a date dimension and also flags which denote weekday, holiday. Would really appreciate help in building a udf for the business days calculation.
Thanks,Hi, Please take a look and tweak accordingly. Best of luck.
--Assuming data dimension table something like the following
--tblDateDim (DT date primary key,
flagHoliday bit,
flagWeekday bit
CREATE FUNCTION fnBusinessDays (
@StartDate DATE,
@EndDate DATE
RETURNS INT
AS
BEGIN
DECLARE @Days INT ;
SELECT @Days = count(*)
FROM tblDateDim --// date dimension
WHERE
( DT BETWEEN @StartDate AND @EndDate) --// dt is date column in the table.
AND --// also flags which denote weekday, holiday
flagHoliday = 0 --// flagHoliday= 1--Holiday;= 0 --workingday/businessday
AND
flagWeekday = 1 --// FlagWeekday = 1--businessday ; =0 --weekend (Saturday and Sunday)
RETURN (@Days)
END
GO
Maybe you are looking for
-
All my recent downloaded programs are in Chinese. Is there any ways I can undo this problem? I using Firefox English GB. == This happened == A few times a week == A month ago
-
Cant get my serial number :-(
Trying to install PS Elements 10 for the first time... entered the redemption code to get my serial number and the error screen is telling me that " The redemption code you entered does not exist". Not sure how to find my serial number now.... This i
-
Hi experts, I am trying to implement BAPI for simulating tcode. FBS1. As a first step, I have implemented the BAPI -> BAPI_ACC_GL_POSTING_POST I did not find any holder where i can give the reversal date. But I could find reason_rev for reversal reas
-
we are creating a scenario from JDBC table to text file. payload seems ok to us but at the time of writing file it's creating empty file.
-
i can open itunes and play music, but as soon as i plug in my ipod, itunes freezes in a way. if i was playing a song at the time it will continue, but i can't select anything, and my ipod doesn't even show up in the side bar, though a box appears abo