As long as you are holding shares at the end of the day before the ex-dividend date, you will get the dividend.