We give a generalization of the Bismut-Elworthy formula, which allows us to cover a larger number of situations than the classical one. It applies to the case of stochastic equations having the diffusion term possibly degenerate, so that the corresponding semigroup cannot have a regularizing effect. It also applies to the case of some stochastic equations both in finite and in infinite dimension whose solutions are not mean-square differentiable with respect to the initial datum.