Welcome Guest Search | Active Topics | Sign In | Register

Difference between 2 dates in "enabled" days Options
tomtom
Posted: Thursday, February 5, 2009 9:21:31 AM
Rank: Newbie
Groups: Member

Joined: 2/5/2009
Posts: 6
Hello,

I just went to discover your library an I may need it for my asp/c# application.

But I have one question about a feature.
My need is to have a calendar with disabled days (week-end, holydays, ...) which is already implemented (great feature ;) ).

But is it possible to calculate easily the number of "enabled" days between two given dates from your Calendar ?
I've checked the API documentation but I didn't find a method which do that.


Thanks in advance
tomtom
eo_support
Posted: Thursday, February 5, 2009 9:26:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,088
Hi,

It should be quite easy for us to provide you a function to do that. Do you want the client side (JavaScript) version or server side (VB.NET/C#) version?

Thanks!
tomtom
Posted: Thursday, February 5, 2009 9:34:11 AM
Rank: Newbie
Groups: Member

Joined: 2/5/2009
Posts: 6
what an impressive promptness !!

I think it's better to have it in the server side version (i'm using c#)


Thanks a lot for your work !
eo_support
Posted: Thursday, February 5, 2009 9:44:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,088
tomtom wrote:
what an impressive promptness !!

We are known for our fast response. :)


tomtom wrote:

I think it's better to have it in the server side version (i'm using c#)
Thanks a lot for your work !

You got it. We will post again when we have the code.
tomtom
Posted: Thursday, February 5, 2009 10:11:06 AM
Rank: Newbie
Groups: Member

Joined: 2/5/2009
Posts: 6
Thanks a lot !
eo_support
Posted: Thursday, February 5, 2009 10:14:32 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,088
Hi,

Below is the code that you can use to count number of enabled days between two dates:

Code: C#
private bool IsDateEnabled(
    EO.Web.Calendar calendar, DateTime date)
{
    //Check against MinValidDate and MaxValidDate
    if (date < calendar.MinValidDate)
        return false;
    if (date > calendar.MaxValidDate)
        return false;

    //Check against DisableWeekendDays
    if (calendar.DisableWeekendDays &&
        ((date.DayOfWeek == DayOfWeek.Saturday) ||
        (date.DayOfWeek == DayOfWeek.Sunday)))
        return false;

    //Check against DisabledDates
    if (calendar.DisabledDates.Contains(date))
        return false;

    return true;
}

private int CountEnabledDays(
    EO.Web.Calendar calendar, DateTime startDate, DateTime endDate)
{
    int n = 0;
    while (startDate <= endDate)     
    {
        if (IsDateEnabled(calendar, startDate.Date))
            n++;

        startDate = startDate.AddDays(1);
    }
    return n;
}


You would call it like this:

Code: C#
int n = CountEnabledDays(
    DatePicker1,                  //the DatePicker/Calendar control
    new DateTime(2009, 2, 1),     //Start date
    new DateTime(2009, 2, 10));   //End date


Note the start date/end date are inclusive. The code also excludes disabled weekend days. If those are different than what you want, it should be fairly easy for you to modify it.

Hope this helps.

Thanks!
tomtom
Posted: Thursday, February 5, 2009 10:21:40 AM
Rank: Newbie
Groups: Member

Joined: 2/5/2009
Posts: 6
OK, thanks for all, I will use it !


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.