In C:

((Start - X + 6) % 7 + NumDays) / 7

It's been 18 years since I've written any Pascal, but it should be something like:

Trunc((((Start - X + 6) Mod 7) + NumDays)/7)

Some testing will, obviously, be required.

--John