You need to sign in to do that
Don't have an account?
stuckonforce
Formula to create number of days between 2 dates
I was looking for a quick formula to calculate the number of days between a create and resolve date.
Any help would be appreciated.
So you want a formula which finds a difference between 2 given dates? Have tried simply finding the difference between 2 dates by simple minusung them , that should work.
In case you think that you need to find which date is greater while substraction just use the following:-
if(d1>d2, d1-d2,d2-d1)
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
So you want a formula which finds a difference between 2 given dates? Have tried simply finding the difference between 2 dates by simple minusung them , that should work.
In case you think that you need to find which date is greater while substraction just use the following:-
if(d1>d2, d1-d2,d2-d1)
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
What is the DataType of the fields you are using? Are they Date, Date/Time, are they both the same, or is one a Date and the other a Date/Time?
If both fields are the same datatype then you can use a simple formula that subtracts the Created Date from the Resolution Date and returns a number. If they are not the same datatype then you are going to have to convert one of the fields to match the datatype of the other, and then do your calculation.
Hi,
They are date fields. One is a creation date and the other is a resolution date. I am trying to calculate the days to resolve.
On another note if I want to create a workflow alert if the creation date plus 2 days if the resoluiton date = null, but the rule didn't like the null bit.
any help would be great.
Thank you
Worked like a charm... Thank you very much...
Okay here's a simple Duration (Days) formula that I did that you can borrow.
Datatype: Formula(Number,1)
[X] Treat blank fields as zeros
Formula:
public void showDays(String startDate, String enddate){
date strtDate = date.parse(startDate);
date ndDate = date.parse(enddate);
integer totalDays = strtDate.daysBetween(ndDate);
integer i;
integer totalWorkingDays;
totalWorkingDays=totalDays;
for(i=1;i<=totalDays;i++){
Datetime dt1 = datetime.newInstance(strtDate.year(), strtDate.month(),strtDate.day());
strtDate=strtDate.addDays(1);
String dayString = dt1.format('EEEE');
if(dayString=='Saturday'){
totalWorkingDays=totalWorkingDays-1;
}
if(dayString=='Sunday'){
totalWorkingDays=totalWorkingDays-1;
}
}
System.debug('Total Days'+totalWorkingDays);
}