Dividend payout qwery

If I buy shares 1 day before Ex. date of dividend and sell it next day ie. Ex date , am I eligible to receive dividend ? As T+2 days take to come shares in demat and I sold it before.

The answer is Yes I will receive dividend , what I learnt from post you share.Is it correct ?