The ex-date is generally a few days ahead of the record date. You should own the stock for that period. After that, the divy is yours to keep.