Explanation 1:
If you buy a stock before the ex-dividend (CD), you will get the dividend. If you buy on or after the ex-dividend date (XD), you won’t get the dividend.
Explanation 2:
The ex dividend date is one business day before the Record Date of the dividend. To be entitled to the dividend, a shareholder must have purchased shares before the ex dividend date.
People who purchase shares on the sharemarket on or after the ex dividend date are not entitled to the dividend. Conversely, if you sell shares on the sharemarket on or after the ex dividend date, you are still entitled to the dividend.