The date on which the dividend eligibility expires is called the ex-dividend date.
It means the person holding the shares on the say 5 January 2022, will get the dividend.
if Person seels the shares on 4 January then he is not eligible to get dividend.
thus only those shareholders has the right to dividend who are sharholders of company at the ex dividend.
Effect of price on ex-dividend date:
the Price on ex-dividend is reduced by the amount of dividend , say
(i) 5 rupees dividend is paid
(ii) Dividend price 1000
then on ex date the price is adjusted 1000-5 = 995