Check your bill. It should have a line that says "billing period". If you are just closing your account (i.e. not porting your numbers), you probably want to close your account on the last day of the billing cycle. If your bill shows that the end of your current billing period is October 17th, it will be the 17th of any other month after that (someone correct me if I'm wrong).
If you are porting your numbers, I would port the number around 3 business days before the end of the billing period. Number porting can take anywhere from 24-72 hours usually. There are cases when it goes through faster and cases where it takes longer. If it takes longer, you will probably go into the next billing period and be billed for unused days. Number porting throws an uncontrollable variable in there for you. With larger carriers, it's usually not a problem. However, I have had a number port take longer because the smaller carrier that I was going to was inundated with many port-in requests around the same time.