Entitlement to a dividend payment depends on the relationship between the trade date and the ex-dividend date.
The record date is the day by which investors must be the owners of the shares so that they are entitled to receive the dividend on the payment date.
Ex-dividend date is a fixed number of days before the record date. The ex-dividend date is set by the local stock exchange (where the stock is listed) rather than by the issuer.
If the trade date is within the cum-dividend (or with-dividend) period, that is, the period between the dividend announcement date and the ex-dividend date, then the buyer of the stock is entitled to receive the dividend (and the seller loses their entitlement to the dividend).
If the trade date is within the period beginning with the ex-dividend date and including the record date, then the buyer is not entitled to a dividend. However, the seller of the stock will receive a dividend payment.
Ex - ex dividend date
Cd - cum-dividend date
Rd - Record date
Ad - Announcement date
Td - trade date or value date
time-line ---->
Ad Cd Ex Rd
Td buyer gets the dividend
Td seller gets the dividend
So if Td is before Ex, buyer gets dividend otherwise seller.