Thursday, February 16, 2012

Beginning and End of Month Dates

Basically what I am trying to do is as Crystal reports goes through records I want it to check a date field to see if they are the first day or last day of the month. If the first day of the month falls on a Saturday, (DayofWeek = 7), I want it to decrement the date by 1 and if the last day of month falls on a Sunday, (DayofWeek = 1), I want it to decrement the date by 2.

Any ideas?The way of distinguishing between both months can be done like this:

If Month({DateField}) <> Month({DateField}+1) //Obviously is -1 to check for the 1st day
if DayOfWeek({DateField})=6 then
Do This
else if DayOfWeek({DateField})=7 then
Do That

I cant recall if DayOfWeek was 1-based or 0-based but the concept applies. :)|||I don't understand what you mean by:
"If Month({DateField}) <> Month({DateField}+1)"

What does this formula do?|||This formula only does the next set of steps IF the datefield is the last day of the month.

Ie, if you ran this today (31/5/05) :
"If Month({DateField}) <> Month({DateField}+1)"

If Month(31/5/05) <> Month(1/6/05)

...which is true. Today is the last day of the month.

If you want to know if the date is the first of the month, use -1.

No comments:

Post a Comment