In the term Ex-Dividend Date, think of “Ex” as “Excludes”, the first date at which the dividend is excluded.
When buying or selling a stock that pays a dividend, the Ex-Dividend date is the first date on which you will be excluded from receiving the dividend. For example, suppose a stock has an Ex-Dividend date of January 28. That means that if you purchase the stock before the market closes on January 27, you will receive the dividend but if you wait until January 28, you will not receive the dividend. Analogously, if you sell the stock before the market closes on January 27 then you will not receive the dividend but if you sell on or after January 28 you will receive the dividend.