When buying stocks the latest you need to buy to get the dividends is the day before the ex-dividend date. If you buy on the ex-dividend date you will miss out on the dividends.
So if you are shorting stocks the latest date you can cover your position and not have to pay out the amount of the dividend is the day before the ex-dividend date.
If you are still short on the ex-dividend date you will have to pay out the amount of the dividend but the stock will reflect a price drop equivalent to the dividend amount. In effect this could result in a zero result overall for you. However, in reality, the actual price drop on and during the ex-dividend date may move down more or less than the dividend amount due to many other market factors.
So, on the ex-dividend date, you may make a gain more than the dividend amount if the stock price drops more that the dividend amount, or you may make a smaller gain than the dividend amount if the price drops less than the dividend amount. In rare cases you may even make a loss on the ex-dividend date if the price moves higher on that day.