There are three very important dates to consider with dividends.
The Declaration Date is date when a company announces it is paying a dividend. It announces the amount per share (for example $3), as well as the Ex-Dividend Date and Payment Date, both of which are typically at least a week or two later.
The Ex-Dividend Date is the day in which purchases of shares are NOT entitled to the declared dividend. Anyone purchasing stock before this date, and holding it until on or after this date, will receive the declared dividend.
The Payment Date is the date when shareholders receive their dividend.
Note: A stockholder does not need to own the stock at the time of the Payment Date in order to receive their dividend. So long they own the stock before the Ex-Dividend Date, they will receive the dividend!