View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove
 
Posts: n/a
Default Date Command to Get the Sunday Before the First of the Month

"Minitman" wrote...
I have a weekly schedule that starts on the Sunday of the week of the
first day of the month (unless it starts on a Saturday). Since this
day will change almost every month, is there a special date command to
accomplish this in a cell formula?


Given a date D, the last day of the previous month is always given by

D-DAY(D)

The last Sunday of the previous month is always given by

D-DAY(D)-WEEKDAY(D-DAY(D),1)+1

IF the following Saturday is the first day of the next month, then the last
day of the previous month is Friday, so

WEEKDAY(D-DAY(D),1)=6

So when the first day of the month is a Saturday, I'd infer you'd want to
treat that as the last day of the final week of the preceding month. If so,
the first Sunday of the month is given by

=D-DAY(D)-WEEKDAY(D-DAY(D),1)+IF(WEEKDAY(D-DAY(D),1)=6,8,1)