Since you sell it on ex-date, you will entitled to the dividend. Normally, the ex-date is the trading date prior to the record date. That means, those who buy on the ex-date will not get delivery by the record date. That means your name will still appear in the register of shareholders on the ex-date and you will be entitled to the dividend on shares.