Thursday, February 16, 2006

VBScript Calculate Working Business Days

After spending an hour searching for this I finally dsecided to just do it myself. It's not that there weren't Any solutions available, just none that did exactly what I wanted to the degree I wanted. And this code is Far from perfect, but does what I need now. The title of this post consists of the keywords I used to find something like what I came up with, based on Many Similar Examples, mostly in SQL. However, I don't want to implement this in SQL until I understand any potential performance hits.

You'll notice there's no date validation. I know, I suck. Although refined a bit I can tell just by looking this could be a lot better, but I've learned the hard way, a less than optimal temporary solution is better than none at all as long as it remains a temporary solution... which means I'll have to have an imporved version in a follow up post :p

'==================================================
'WRKDAYSBETWEEN
'
'Calculates number of working days (Mon-Fri) between 2 dates
'
'==================================================
Function WrkDaysBetween(dtStart, dtEnd)

totalDays = DateDiff("D", dtStart, dtEnd)
totalWeeks = DateDiff("W", dtStart, dtEnd)

'COUNT DAYS IN FIRST WEEK -WEEKENDS
Select Case WeekDay(dtStart)
Case vbMonday
daysFirstWeek = 5
Case vbTuesday
daysFirstWeek = 4
Case vbWednesday
daysFirstWeek = 3
Case vbThursday
daysFirstWeek = 2
Case vbFriday
daysFirstWeek = 1
Case vbSaturday
daysFirstWeek = 0
Case vbSunday
daysFirstWeek = 0
End Select

'COUNT DAYS IN END WEEK -WEEKENDS
Select Case WeekDay(dtEnd)
Case vbSaturday
daysLastWeek = 0
Case vbSunday
daysLastWeek = 0
Case vbMonday
daysLastWeek = 0
Case vbTuesday
daysLastWeek = 1
Case vbWednesday
daysLastWeek = 2
Case vbThursday
daysLastWeek = 3
Case vbFriday
daysLastWeek = 4
End Select

modDays = totalDays Mod 7

'GET DAYS OUTSIDE OF WEEKS
if modDays < daysFirstWeek + daysLastWeek then
oddDays = modDays
else
oddDays = daysFirstWeek + daysLastWeek
end if 'modDays < daysFirstWeek + daysLastWeek


if totalDays < daysFirstWeek then
wrkDays = totalDays + (totalWeeks * 5)
else
wrkDays = oddDays + (totalWeeks * 5)
end if 'totalDays < daysFirstWeek

WrkDaysBetween = wrkDays

End Function
'==================================================

Addendum: This link was NOT there yesterday. Damn ever changing web...

Labels:

Tuesday, February 14, 2006

I LOVE O'Reilly Safari Bookshelf

I read a lot of technical books. Unfortunately, I buy even more. Whether for reference or ramp up, I get several books on any given subject and consume until I find what I need or feel "comfortable" with the topic at hand. This has lead to a lot of wasted paper, not to mention the occasional frustration of newer editions coming out a month or two after I finally pick up a title (which means I hadn't even started reading it yet).

Although I frequent several publishers, I've been a fan of O'Reilly books for a while. Yes the I think the animals are cool. Cooler still, is the regularly reinforced reputation for solid content.

I don't remember how I was originally introduced to the SB, but it seemed too good to be true. I spend a lot of time searching the internet for relevant and recent technical info. There's a lot of smart people out there who are willing to share. (I hope to be worthy of becoming one of them some day.) This site... no, this Service advertized the ability to search published books. The number of times I wanted to do this flashed before my eyes. I tried it "Free for 14 days". I was hooked in the first couple hours.

I could go into detail about the sheer number of books available or the incredible range of information available. Instead, I'll give the current count (3616) list the categories (mmm cut & paste *homeresque gargle*):

Applied Sciences
Artificial Intelligence
Business
Certification
Computer Science
Databases
Desktop Applications
Desktop Publishing
E-Business
E-Commerce
Enterprise Computing
Graphics
Hardware
Human-Computer Interaction
Internet/Online
IT Management
Markup Languages
Multimedia
Networking
Operating Systems
Programming
Security
Software Engineering

The reason I truly love the Safari Bookshelf is because of how it's transformed how I consume information. As a web developer, I read a LOT of web pages. I'm a little afraid to think how many. What's never occured to me is the ease at which I can intake massive amounts of info from the web. How is that different any other source? When I pick up a technical book (which with most is a mini-workout in and of itself), I read as much as I can in a sitting, put in a bookmark and come back to it when:
1) I need info from that book.
2) I happen to have that book and time to read
3) I happen upon that book and decide to pick up again
I don't necessarily complete a chapter or a section of a chapter before stopping and a bookmark means I stopped at some point within two pages. I'm also limited to the number of books I can afford or want to carry around.

Enter the Safari Bookshelf. As long as I have an internet connection (what kind of web developer would I be if I didn't have access everywhere :p), I have access to 28 books right now. My queue tops out at 30. The amazing thing is ,depending on my focus, I'm actually reading all of them. I'm reading some from cover to cover and others for reference. In amount of high quality info on hand, I fond the contents noticably more readable. I need this next statement to stand out as it is a pivotal point...

Unlike ebooks, which are electronic, page for page, reproductions of their printed counterparts, books on safari have their own unique layout thats broken into logical sections without pritnted material constraints.

Each topic of a book is given it's own page. Some topics are a paragraph. Some topics are an entire chapter. Different books break down in different ways, but whats consistent is that when you get to the bottom of a page, you've consumed a packaged chunk of logic that feels much closer to what the author intended. It's like the difference between a normal conversation and having to pause for a minute each time the combined number of words reached a certain limit. Although, not show stopping, when that restriction is gone, you feel the difference.

Using FreeMind (a free mind mapping software) I've taken to logging the books I've gone through as there's no history I can find. An export of this mind map is avaiable here.

Despite my love of the service, I recognize some room for improvement. Their download options make NO sense to me. After the first couple of months of unused tokens I decide to used them on Eclipse Distilled. 3 months of tokens (the most you can have at once) got me some of the book. Once in PDF format I realized I'd moved backwards to the limitations of printed material and not even a complete work. Soon after I changed subscriptions to remove tokens. Haven't missed them once.

Labels: , , ,