There is no specified/legal amount of time you must own a stock before you are able to capture the dividend. When a company declares a dividend, the board of directors decided how much it will pay and on what day it is payable. They also declare a "record date". Anyone who owns the stock within 2 days after that record date (called the ex-date) is eligible to receive the dividend. If a company determined that the record date was March 1, as long as you owned it by March 3, you would recieve it.
But, be aware that when a company pays a dividend, all else equal, the price of the shares goes down by that amount on the ex-date (because the company no longer has the cash on its balance sheet and is now worth less). So, trying to time the dividend can result in tax consequences and little financial gain. Good luck!