To be paid a stock dividend, you must own the stock on the day that the corporation's board of directors names as the record date, also known as the date of record.
For example, if a company declares a dividend of 50 cents a share payable on September 1 to shareholders of record as of August 10, you must own the shares on August 10 to be entitled to the dividend.
To be the legal owner on the record date you must buy the stock at least three business days before the record date. That is the last day on which trades will settle on the record date.
If you buy the stock after that day, you are buying the stock ex-dividend, which means you are not entitled to the dividend. The first day the buyer is not entitled to receive the dividend is called the ex-dividend date and is currently two days before the record date in most cases.