We consider an optimal control problem of Mayer type and prove that,under suitable conditions on the system, the value function isdifferentiable along optimal trajectories, except possibly at theendpoints. We provide counterexamples to show that this property may failto hold if some of our conditions are violated. We then apply our regularityresult to derive optimality conditions for the trajectories of the system.