The procedure for deriving the equation for the discharging capacitor is similar, though you have to use i = -dq/dt because dq/dt is negative for a discharging capacitor, by definition.