This is a migrated thread and some comments may be shown as answers.

Expression, datediffday and week end

2 Answers 42 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ERIC
Top achievements
Rank 2
ERIC asked on 30 Jul 2013, 06:37 PM
Hello,

Is it possible to count the days separating two dates excluding weekends ?
Sorry if the topic has already been discussed, I did not find anything similar on the forum

Thank you in advance !

Best regards,

Eric

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 02 Aug 2013, 09:15 AM
Hi Eric,

Thank you for writing.

To calculate business days only, you can use a custom expression function like the following one:
public class CustomExpressionContext : Telerik.Data.Expressions.ExpressionContext
{
    public double GetBusinessDays(DateTime startD, DateTime endD)
    {
       double   calcBusinessDays = 1 + ((endD - startD).TotalDays * 5 - (startD.DayOfWeek - endD.DayOfWeek) * 2) / 7;
 
        if ((int)endD.DayOfWeek == 6)
            calcBusinessDays--;
        if ((int)startD.DayOfWeek == 0)
            calcBusinessDays--;
 
        return calcBusinessDays;
    }
}

You can apply the function to the column like this:
Telerik.Data.Expressions.ExpressionContext.Context = new CustomExpressionContext();
this.radGridView1.Columns[2].Expression = "GETBUSINESSDAYS(col1,col2)";

I hope this information helps. Should you have any other questions, I will be glad to assist you.

Regards,
Dimitar
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
ERIC
Top achievements
Rank 2
answered on 02 Aug 2013, 02:03 PM
Hi,

Thank you very much it works as desired!

Best regards,

Eric
Tags
GridView
Asked by
ERIC
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
ERIC
Top achievements
Rank 2
Share this question
or