Honda Motorcycles - FireBlades.org banner

1 - 8 of 8 Posts

·
Registered
Joined
·
12,126 Posts
Discussion Starter #1
I'm having brain fade and can't seem to get this working correctly. :rant:

I need to calculate the number of elapsed minutes between two datetime variables. BUT, it needs to only include times between 8am and 5pm on weekdays.

So if the starting datetime is at 5:01pm, it doesn't start counting until 8am the next weekday morning.

Or, if the ending datetime is at 6:30am, the counting would stop at 5pm the previous weekday.
 

·
Registered
Joined
·
12,126 Posts
Discussion Starter #2
Got it. I'm sure it could be optimized, but it's working. Decided to have it return Minutes since I needed to be able to display Hours:Minutes elapsed and it was easier to calculate this way.

Code:
Public Function fnReturnMinutes(datStart,datEnd,datDayStart,datDay  End)

	If TimeValue(datStart) > datDayEnd Then
		datStart = CDate(DateValue(DateAdd("d",1,datStart)) & " " & datDayStart)
	ElseIf TimeValue(datStart) < datDayStart Then
		datStart = CDate(DateValue(datStart) & " " & datDayStart)
	End If

	If TimeValue(datEnd) > datDayEnd Then
		datEnd = CDate(DateValue(datEnd) & " " & datDayEnd)
	ElseIf TimeValue(datEnd) < datDayStart Then
		datEnd = CDate(DateValue(DateAdd("d",-1,datStart)) & " " & datDayEnd)
	End If

	intMinutes = 0
	
	If DateValue(datStart) = DateValue(datEnd) Then
		If WeekDay(datStart,vBSaturday) > 2 Then
			intMinutes = DateDiff("n",datStart,datEnd)
		End If
	Else
		If WeekDay(datStart,vBSaturday) > 2 Then
			intMinutes = DateDiff("n",datStart, CDate(DateValue(datStart) & " " & datDayEnd))
		End If

		datLoop = DateAdd("d",1,datStart)
		Do While DateValue(datLoop) < DateValue(datEnd)
			If WeekDay(datLoop,vBSaturday) > 2 Then
				intMinutes = intMinutes + DateDiff("n",datDayStart,datDayEnd)
			End If
			datLoop = DateAdd("d",1,datLoop)
		Loop

		If WeekDay(datEnd,vBSaturday) > 2 Then
			intMinutes = intMinutes + DateDiff("n",CDate(DateValue(datEnd) & " " & datDayStart),datEnd)
		End If
	End If
   
   fnReturnMinutes = intMinutes
   
End Function
 

·
Registered
Joined
·
1,892 Posts
Oh yeah???!!!! Well I marsupialized an intrabony cyst with a Rusch tube today.


Neither one of us knows what the other is talking about, but I thought you'd appreciate a response other than your own to your own thread. :D
 

·
Registered
Joined
·
2,704 Posts
Got it. I'm sure it could be optimized, but it's working. Decided to have it return Minutes since I needed to be able to display Hours:Minutes elapsed and it was easier to calculate this way.
Yeah, it could probably be optimized a bit. I'd put another "n" or an if statement in there somewhere.
 

·
Registered
Joined
·
14,224 Posts
Oh yeah???!!!! Well I marsupialized an intrabony cyst with a Rusch tube today.


Neither one of us knows what the other is talking about, but I thought you'd appreciate a response other than your own to your own thread. :D
I followed most of Conq's and you are talking of a medical procedure to remove a cyst :idunno: Keep up there :D
 

·
Registered
Joined
·
1,892 Posts
My first introduction to computer programming was during a college math course and the instructor told us to figure the solution to the problem using the college computer lab. So I go there and there is this machine about the size of a 1960 Buick Electra 225 and all it does is punch holes in cards. Hmm, so how do I know which holes to punch???!!!! It may be possible for a monkey to type out the works of Shakespeare eventually, but I spent two days putting holes in cards and the only thing I could reliably reproduce was a lockup. I wasn't gonna try on day three because there was a kegger scheduled, so I just took the hit on the assignment. I could have been as famous as Einstein if I had known what I was doing, but the Purple Passion in the bathtub and the hotties at the kegger were way worth more than the investigative initiative (and pitfalls) into higher learning.

After the massive hangover that lasted three days, I decided that geekdom was not for me and I pursued the path to become a surgeon. I really think the computer world owes me a debt of gratitude for that.

This was at a time my future wife was working at Mutual of Omaha as a keypunch operator. She could tell me what to do (and still does) but didn't know anything about matrix calculus, and I didn't know anything about telling some machine how to solve a problem. Seemed to me like I could do it in less time on paper than trying to figure out how to work this computer. This was about the same time that everyone was getting used to the lag in the middle of a song when the 8 track tape switched to the next track on the loop. (We should do a poll as to how many members don't have a clue as to what I'm talking about.)

I am totally in awe about how these machines can be programmed to do the things they do.

Anywhooo, I was just trying to let the Big Guy know somebody read his thread so he didn't feel left out!!!! :rotfl:
 
1 - 8 of 8 Posts
Top