Just to add a bit to what ronn38 already elegantly explained.
At the Ex-Dividend date 2 things usually happen:
1. The price of the stock at the opening will be lower by the dividend amount.
2. All the people that owned the stock at the close of the previous day will be marked for dividend payments.
Another date to note is the dividend payment date.
At this date all the people that owned the stock at the close of the day before the Ex-Dividend date will be paid the dividend.
Back to DHY example.
Here is what Nasdaq has to say about DHY dividend history:
http://www.nasdaq.com/symbol/dhy/dividend-history
Ex/Eff Date Type Cash Amount Declaration Date Record Date Payment Date
8/14/2014 Cash 0.024 8/1/2014 8/18/2014 8/22/2014
The Ex-Date is Thursday 8/14/2014 which means if you want to get the dividends than you need to own the stock at the close of Wednesday 8/13/2014.
On the Payment-Date 8/22/2014 everybody who owned DHY at the close of Wednesday 8/13/2014 will get $0.024 dividend for every share he owned at that time.
Example:
If you owned 100 DHY shares at the close of 8/13/2014 and then purchased another 100 shares between the open of 8/14/2014 and 8/22/2014 you will get dividend only for the first 100 shares you owned.
Example 2:
If you purchased 100 DHY shares after the close of 8/13/2014 than you will not get dividends at all.