You have to be holding the shares prior to the ex-dividend date to be eligible. You can sell from the ex-dividend date onwards though.