If you purchase before the ex-dividend date, you get the dividend. If you purchase a stock on its ex-dividend date or after, you will not receive the next dividend payment. If you sell your stock before the ex-dividend date, you also are selling away your right to the stock dividend.
With a significant dividend, the price of a stock may move up by the dollar amount of the dividend as the ex-dividend date approaches and then fall by that amount after the ex-dividend date. A stock that has gone ex-dividend is marked with an "x" in newspapers on that day.
In other words, the "ex-dividend date" or "ex-date," is the final date dividends will be paid to the owner of the stock. If a stock is sold after that date, all succeeding owners will not receive that dividend.