The general solution for all possible input voltage functions v(t):
q(t)= the convolution integral of C⋅(1−exp(-t/RC)) and your v(t). C and the series resistor are assumed to be constant.
The full understanding of the solution and how to derive it unfortunately needs differential and integral calculus worth about one year university math studies
If you write out the convolution integral, you easily see, that it's an infinite sum (exactly the limit) of a series of small incremental responses that are all individually calculated by using your formula for the DC input. The input voltage is considered to be the sum of small inividual increments which all can be considered to be independent constant voltages. This thinking is acceptable for linear circuits and this is one.
Note that each increment has its own starting time.