C
Claire
I have a somewhat ugly situation. Our year/first day/first week of the year
changes depending on which day of the week January 1st is. My goal is
twofold:
1. To be able to find the first day of the yearly payroll for any given
date (and the corresponding end of that year)
2. To be able to find the payroll week number for any date (ie 12/14/08 is
week 51).
The first week of the year begins on second Monday before the first Friday
of the new year. IE 2009 starts on Monday December 22, because the first
2009 Friday is January 2 (the Monday before that is Dec 29, and the second
Monday before it is Dec 22).
I have translated this to mean that if the weekday (with Monday as the first
day of the week) of January 1st is <6 (ie Mon-Fri), then the first day will
be the Monday the week before January 1st. If the weekday is >=6 (Sat,Sun),
the first day of the payroll year is the Monday of that week.
I figure if I can figure out how to calculate the first day of the year,
then the last day of that year and the week number of the year should be more
manageable. I have pasted my first attempt before. The arguments are not
correct at this time (which doesn't surprise me given how nested it is) but I
haven't dealt with that yet, as I'm hoping someone out there has an idea of
how to simplify this mess.
Thank for any help, and here's the crazy first attempt:
iif(weekday(dateserial(datepart("yyyy",#12/14/08#),1,1),2)<6,
dateadd("ww",-1,(dateserial(datepart("yyyy",#12/14/08#),1,1)
-weekday(dateserial(datepart("yyyy",#12/14/08#),1,1),2)+1),
(dateserial(datepart("yyyy",#12/14/08#),1,1)
-weekday(dateserial(datepart("yyyy",#12/14/08#),1,1),2)+1)))
changes depending on which day of the week January 1st is. My goal is
twofold:
1. To be able to find the first day of the yearly payroll for any given
date (and the corresponding end of that year)
2. To be able to find the payroll week number for any date (ie 12/14/08 is
week 51).
The first week of the year begins on second Monday before the first Friday
of the new year. IE 2009 starts on Monday December 22, because the first
2009 Friday is January 2 (the Monday before that is Dec 29, and the second
Monday before it is Dec 22).
I have translated this to mean that if the weekday (with Monday as the first
day of the week) of January 1st is <6 (ie Mon-Fri), then the first day will
be the Monday the week before January 1st. If the weekday is >=6 (Sat,Sun),
the first day of the payroll year is the Monday of that week.
I figure if I can figure out how to calculate the first day of the year,
then the last day of that year and the week number of the year should be more
manageable. I have pasted my first attempt before. The arguments are not
correct at this time (which doesn't surprise me given how nested it is) but I
haven't dealt with that yet, as I'm hoping someone out there has an idea of
how to simplify this mess.
Thank for any help, and here's the crazy first attempt:
iif(weekday(dateserial(datepart("yyyy",#12/14/08#),1,1),2)<6,
dateadd("ww",-1,(dateserial(datepart("yyyy",#12/14/08#),1,1)
-weekday(dateserial(datepart("yyyy",#12/14/08#),1,1),2)+1),
(dateserial(datepart("yyyy",#12/14/08#),1,1)
-weekday(dateserial(datepart("yyyy",#12/14/08#),1,1),2)+1)))