how long do i need to own a stock before the ex-date to get the dividend
Ex-dividend date - On (or after) this date the security trades without its dividend. If you buy a dividend paying stock one day before the ex-dividend you will still get the dividend, but if you buy on the ex-dividend date, you won't get the dividend. So, if you want to sell a stock and still receive a dividend that has been declared you need to sell on (or after) the ex-dividend day.