Jump to content

This topic is 8516 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hey kids.

I need a calculation that will look at a date and return the Monday of that week. e.g. If date = 8/18/2001, WeekOf_c = 8/15/2001

I know that I can do this with a long Case statement, testing for which day of the week it is, then subtracting the appropriate number:

Case(DayName(date) = Tuesday, date - 1,

DayName(date) = Wednesday, date - 2,

... and so on

but is there any other way. I like to keep my calculations as short as possible.

Thanks, eh.

Paul

Posted

Oh my God, rd. I bow in the presence of your genius.

I tried it out, and it works, of course, but for the life of me, I can't figure out why it works.

Please enlighten a simple creature.

... and thanks.

Paul

Posted

Case(DayName(date) = Tuesday, date - 1,

DayName(date) = Wednesday, date - 2,

... and so on

The answer why is in your "and so on" which indicates you recognize there is a pattern (i.e., date -1, date-2, date-3, etc.) The number you subtract from date can be simplified to DayofWeek - 2, since Monday is the second day of the week (If Monday(2), subtract 2-2, or none. If Tuesday(3) subtract 3-2, or one). Then you just need a special case for Sunday. If the week began with Monday (i.e., DayofWeek(Monday)=1 instead of 2), you could do it without the Case.

This topic is 8516 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.