.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How can I calculate the Number of Weekends between two dates

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
I need to be able to figure out the number of Saturdays and the number of Sundays between two dates.  I know that I can do this by looping through the series of dates between the start date and end date.  Years ago I saw a piece of code that an ex-co worker wrote that accomplished this task using a formula.  The formula was extemely effecient.  Unfortunately I no longer have access to this code.  Does anyone have an algorithm that will perform this calculation that I can make use of?  Thanks

View Complete Post

More Related Resource Links

How can I calculate the Number of days between two dates Monday to Friday


    I am using following code for Robert's Posted Code (Url:http://forums.asp.net/t/1142378.aspx) But this is for only calculate weekends saturday and sunday can any one tell me how 
I get Number of days between given two dates Monday to Friday.

private const int MONDAY = 1; private const int TUESDAY = 2; private const int WEDNESDAY = 3; private const int THURSDAY = 4; private const int FRIDAY = 5; private const int SATURDAY = 6; private const int SUNDAY = 7; /// <summary> /// Observe that the method calculates by including the start day, but excludes the end day /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> private void GetWeekendDaysBetween(DateTime startDate, DateTime endDate,out int saturdays,out int sundays) { saturdays = -1; sundays = -1; if (endDate < startDate) return; TimeSpan timeBetween = endDate.Subtract(startDate); int weekendsBetween = timeBetween.Days / 7; sundays =

How to create a calculation in a list - Calculate the number of days between two dates


I have a calculated column in a list called Days Open. This column contains the number of days between today (Sysdate) and another column called the Effective Date. Therefore, if Sysdate is 11/16/2010 and the Effective Date is 10/14/2010, how do I calculate the number of days between the two dates?

I tried using this formula: =TEXT(Sysdate-[Effective Date],"h") and then I tried =INT(Sysdate-Effective Date) & TEXT(Sysdate-Effective Date, ":hh:mm")

Neither formula worked. I hope it is something real simple that I am missing here. Any help you can provide will be highly appreciated!

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 this

I need an expert sql server, number of working day during two dates.

Hi, I've this table below, And I need to calculate between two dates, the number of working day. This table is like that I can't change it. So mondayamid for monday morning mondaypmid for monday afternoon and so on... Thus fields contain the id of the type of day, 1 for working day, 2 for holiday, 3 for sick. And there is the number of the week on a year. Please I've no idea how to calculate the number of workday or half day between two dates. THANKS SO MUCH SELECT       [OwnerId]       ,[mondayamid]       ,[mondaypmid]       ,[tuesdayamid]       ,[tuesdaypmid]       ,[wednesdayamid]       ,[wednesdaypmid]       ,[thursdayamid]       ,[thursdaypmid]       ,[fridayamid]       ,[fridaypmid]       ,[saturdayamid]       ,[saturdaypmid]       ,[sundayamid]       ,[sundaypmid]       ,[weekid]       ,[Notesid]   FROM attendanceentry where owneridname like '%Julimian%' So every half of day, I've the id of the type of the day that people took. 1 - working 2

find number of sundays between two dates using sql

can i find total number of sundays between two dates using sql? or total number of days between two days except sundays

How do i calculate no of days between two given dates

Dear All, My requirement is used to find no of days between two given dates and time(from date and to date). using c#. Thanx in advance Dinesh        

How do i calculate no of days between two dates n two times Using C#

Dear All, i got the task to find no of days between two dates n Two given times Using C# I have four fields( columns) Such as follows, Arrival Date, Arrival Time, Leaving Date and Leavingtime. Example: Leaving Date-24/08/2010,Leaving Time- 08:00 , Arrival Date- 12/09/2010 ,Arrival Time-16:00, From the above Example i need to find No of days. Note : Days should calculate from Leaving time to arrival time (with reference to above example it means if he starting at 8:00 o clock(24/08/2010)  in the morning the next day eight o clock will be one day(8:00/ 25/08/2010)) Thanx in advance    

Caculated column formula for Workdays between two dates ? Excluding weekends? DateDiff

This gives me the number of days between two days.. great=DATEDIF([Completed],[Issued],"D")is there any way to exclude weekends?

How to calculate difference between two dates in years


hi all, 

i need to know if, given a birth date, a person has more than x years. Thats mean, the client must entry a date in a textbox and i need to know if the persona has more than 18 years. 

Thx in advance

How to calculate working hours betwwen two dates?


Working days - Mon-Fri and Working hours - 9 Am to 5 Pm

Date1                                       Date2                                                Working Hours

Thur, 14-Oct-10 11.30 Am          Thur, 14-Oct-10 5.00 Am                     5.30

Fri,  15-Oct-10 11.30 Am            Mon, 18-Oct-10 5.00 Am                      13.30

Mon,  18-Oct-10 11.30 Am          Mon, 18-Oct-10 6.00 Am                      5.30


Thanks & Regards, PSWA

need a help on T-SQL query to calculate number of instances in a month



     I need to write a T-SQL query where i need to get number of bugs logged in our database per month. and i am using the below query for that

Select count(ID) as [No. of Bugs], (datename(

How to calculate total work hours between dates?

I am in the process of creating a calendar.  This calendar is to track leave hours for employees.  For example if a person takes leave for 2.5 days then the formula would calculate 8hrs per day and 4 hours for half a day = 20hrs.  I have part of the formula I believe "=TEXT([End Time]-[Start Time],"h")".  The problem is that it does not count multiple days and just not working right. Any advice would help.

function to calculate number of business days in a month for a given date


hi ,

Is there any function to calculate number of business days in a month for a particular date.  my input would be just a single date



Find week number in xpath from two dates in SharePoint 2010



I am trying to determine the week of the year from two dates. The first date will be the first day and month of that year (e.g. 01/01/2005) and the second will be the date of a document(05/05/2005). We tried to accomplish this same task within SharePoint, not using the SP Designer, however, we could not because we could not utilize the name column. Anyhow below is what I got so far. I search for a date function to perform subtraction but could not find any. Thank in advance.


ddwrt:FormatDate(substring($thisNode/@FileLeafRef.Name,1,10),1041,1) -ddwrt:FormatDate(concat(substring($thisNode/@FileLeafRef.Name,1,4),'-01-01'),1041,1)

Convert English to Arabic number without changing any regional settings in .net

Well, most applications that I worked with was multilingual that supports English UI and Arabic UI.

And one of the major issue that we have faced is displaying Arabic numbers without the need of changing the regional settings of the PC.

So the code below will help you to display Arabic number without changing any regional settings.

Calculate distance, bearing and more between Latitude/Longitude points

This page presents a variety of calculations for latitude/longitude points, with the formulæ and code fragments for implementing them.

All these formulæ are for calculations on the basis of a spherical earth (ignoring ellipsoidal effects) - which is accurate enough* for most purposes. [In fact, the earth is very slightly ellipsoidal; using a spherical model gives errors typically up to 0.3% - see notes for further details].

How to calculate the distance between two points on the Earth

We offer many Global Database Products that you can use with the below formulas to calculate distances and many other uses. Not sure how to use distance calculations or global databases within your company? See our Global Database Examples for more information on how to use our data within your industry. Be sure to Download a Free Sample of one of our many Global Database Products.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend