It depends DOLPHY. According to the SEC documents there are Cash dividends and stock dividends. Each is treated differently.
In a cash dividend, the ex-date is 2 days before the record date. So, you are good if you hold past the record date because the ex-date has already passed.
In a stock dividend, the ex-date is 1 day after the pay date. The pay date is the day you get the dividend. So, in this case there is a lag time between the record date and ex-date. You have to be a holder on or before the record date and you CAN'T be a seller before the ex-date.