There is quite a bit of confusion in the market about the rules for earning dividends. I have recently heard from someone that you have to own stock for 30 days (or maybe for 45 days) or you don't get the dividend. This isn't true. There is only one day when you have to be recognized as the owner: the record date.
Here's how it works. The company selects a "record date" and anyone who is the registered owner of stock on that date gets the dividend. Once the record date is set, the ex-dividend date is also set to fall two days before record date. This is done because it takes three business days to settle stock transfer. So you have to buy shares of stock before ex-dividend date so that you will be the stockholder of record three days later, on the record date.
You can sell your shares on ex-dividend date or any date after. As long as you bought shares before ex-dividend date, you get the dividend.
Payment date comes after, often as much as a month later. For irregular payments (semiannual or annual) payout date might be a matter of months.
The stock is expected to be reduced by the amount of the dividend on the record date. But in fact, this often becomes invisible. For example, a 30 cent dividend might be offset by normal market activity including a possible offsetting rise in price. So many references to this offsetting decline in the stock price make it sound like a disaster, when in fact the amount of the dividend is so small that the offset in the stock price is likely to have little lasting effect.
So there isn't really that much to remember. You have to buy shares before ex-date in order to earn the dividend. And you can sell any time on or after ex-dividend date and still be acknowledged as stockholder of record. It really isn't as complicated as it often is made out to be.
To gain more perspective on insights to investing observations and specific analysis, I hope you will join me at ThomsettStocks.com where I publish many additional articles. I also maintain a virtual portfolio of stock at ThomsettStocks.com. For new trades, I usually include a stock chart marked up with reversal and confirmation, and provide detailed explanations of my rationale. Link to the site to learn more.