Hi everyone :)
I want to calculate the difference (in days) between 2 dates (user will select them from a calendar). But it should exclude weekends (Saterday & Sunday).....
Thanks :)
Printable View
Hi everyone :)
I want to calculate the difference (in days) between 2 dates (user will select them from a calendar). But it should exclude weekends (Saterday & Sunday).....
Thanks :)
Hey, kid. Where's your best body Butch Cassidy, ha?
;-)
Anyway, you may use DateDiff function and substract 2 from the result.
McGenius, maybe you should reconsider your name here.;)
You can't just substract 2, because you must figure out the number of weekends first.
Here is a function i used before. I believe i stole half of it from this forum:D
VB Code:
Public Function NettoWorkdays(ByVal dtmStart As Date, ByVal dtmEnd As Date) As Integer 'This function calculates the number of working days (monday to friday) between 2 dates, 'including the first and the last day Dim intDays As Integer Dim intSubtract As Integer ' if end is smaller then start return -1 If dtmEnd < dtmStart Then NettoWorkdays = -1 Else ' Get the start and end dates to be weekdays. While WeekDay(dtmStart) = vbSaturday Or WeekDay(dtmStart) = vbSunday dtmStart = dtmStart + 1 Wend While WeekDay(dtmEnd) = vbSaturday Or WeekDay(dtmEnd) = vbSunday dtmEnd = dtmEnd - 1 Wend If dtmStart > dtmEnd Then ' Sorry, no Workdays to be had. Just return 0. NettoWorkdays = 0 Else intDays = dtmEnd - dtmStart + 1 ' Subtract off weekend days. Do this by figuring out how ' many calendar weeks there are between the dates, and ' multiplying the difference by two (because there are two ' weekend days for each week). That is, if the difference ' is 0, the two days are in the same week. If the ' difference is 1, then we have two weekend days. intSubtract = (DateDiff("ww", dtmStart, dtmEnd) * 2) NettoWorkdays = intDays - intSubtract End If End If End Function
Hey, you dummy, you better think before sending this s**** to me. If you're a PROGRAMMER then all need is an idea - the rest is upto capability if your brain and willingness of doing new things.Quote:
Originally posted by Frans C
McGenius, maybe you should reconsider your name here.;)
You can't just substract 2, because you must figure out the number of weekends first ...[/Highlight]
Thanks for the replies dudes :cool:
McGenuis : Thanks ... my best bod cassidy is @home (I got 2 , the wife and the basset hound).... and the Basset is probably still pi$$ed because I she took all the bed covers last night, and when I moved her she growled like a lion :)
Frans C: Thanks for the code... I needed it quickly so I didn't have time to figure out how to do it :o