As a company declares the dividend data, it makes a record of the date when the company books will show giving the dividends to the shareholder. There are three dates mentioned in the records – the ex dividend date, the date of record and the pay date. The ex dividend date refers to two business days before the record date. If you buy a stock on the ex dividend dates (or later), you will not get the dividend. It refers to the time phase between the announcement and payment of the money; while, the date of record is the day when the shareholder must officially own the share to be entitled to get the dividend. The price of stocks gains before the date and once the declaration of dividend are made, it declines.
Some investors use the term buying dividends, where they buy stocks before the date only to sell once the dividends are declared but this rarely works as it takes time of the shares to show up in your account, and for buying and selling you need to pay commission, which makes such trades unprofitable.