Buying shares to get the…

Buying shares to get the dividend.

Just wanted to check if buying shares on ex-div date would be sufficient to get the dividend.
Or do I need to buy a day early to account for the time to settle the trade?