First Day of Year in DatePart function

T

Tom Stoddard

I'm frustrated with what I consider to be an inconsistency in the DatePart
function.

My company keeps track of certain business functions by 4 week periods with
the weeks running from Friday to Thursday. If I want to figure our what
period a specific date is in I use the DatePart function to find the week of
the year and I divide by four (with some additional tweaking of course).
Here's my frustration:

If I do this:

DatePart("ww","12/31/06",vbFriday,vbFirstFourDays) the function returns 1 as
the week of the year, meaning the first week of 2007. This is what I would
expect since help states that using the constant vbFirstFour Days will
"Start with the first week that has at least four days in the new year."

However, if I do this:

DatePart("ww","12/31/06",vbFriday,vbFirstJan1) the function returns 53 as
the week of the year, meaning the last week of 2006. This does not make
sense since help states that using the vbFirstJan1 constant will "Start with
week in which January 1 occurs (default)." In other words, 1/1/07 occurs in
the same week as 12/31/06 when looking at weeks starting on Fridays. Why
then would 12/31/06 not be part of week 1 of 2007 as it is when using the
vbFirstFourDays constant?

I can code around this but what I don't understand is why the
vbFirstFourDays constant will spill over into the previous year but the
vbFirstJan1 will not. I can see reasons why you would want it to work both
ways but why would one work one way and the other do the opposite. It seems
to me that there needs to be 2 additional options here. Something like:
vbFirstJan1Full, vbFirstJan1Partial, vbFirstFourDaysFull, and
vbFirstFourDaysPartial.

Ok, I've vented now. This post probably needs no reply but if there is some
reasoning that I'm not aware of, I'd like to hear it.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top