In this article,we consider the classically ill-posed problem of numerical differentiation in the framework of the PDEs-based numerical differentiation methods.A novel scheme for the first and second order numerical derivatives is proposed by the approach of an inverse source problem for a time-fractional diffusion equation.The numerical differentiation problem is transformed into the inverse source problem which induces a regularized optimization problem.The convergence rates of regularization solutions are derived under the a priori and a posteriori strategies for selecting regularization parameters,respectively.Finally,several examples are given to verify the efficiency and stability of the proposed scheme.