Date of transaction, not settlement...Actually it probably doesn't matter. settlement to settlement or transaction to transaction.
Also, the wash rule applies to 30 days purchase before OR after the sale, so you can't buy new shares and sell the old shares 30 days later and declare the loss. The wash rules still applies.