Dynamic flux balance analysis (dFBA) models are very popular in systems biology because of the many possible applications. dFBA consists of dynamic mass balance equations that describe the concentration of external metabolites and an optimization model to compute the internal flux distribution of the cell. Here, we applied a nonlinear programming formulation for solving dFBA models. The ODE system is discretized using the orthogonal collocation technique and the optimization problem is replaced by its first-order optimality conditions. In addition, an adaptive mesh scheme is applied to improve performance by efficiently handling changes in the active set of constraints. This formulation ensures total differentiability of the model, which can be solved by large-scale solvers and take advantage of automatic differentiation packages. The new approach presents results equivalent to state-of-the-art methods and outperforms them in dynamic optimization problems by avoiding calling an external solver to handle the embedded optimization model.