The capacitance of a conductor is given by, $q = CV$.
While the capacitor is connected across a battery, charges come from the battery and get stored in the capacitor plates. But this process of energy storing is step by step only.
In the beginning, the capacitor does not have any charge or potential.
i.e. $V = 0$ and $q = 0$.
After applying the potential from the battery, the work has to be done to transfer charges onto a conductor, against the force of repulsion from the already existing charges on it. This work is stored as a potential energy of the electric field of the conductor.
Suppose a parallel plate capacitor having capacitance $C$ to store the charge $q$ when connected across the cell of potential $V$. So, we have
$q = CV$ .......... $(i)$
When charge $dq$ is passed to the capacitor at constant $V$, then small amount of workdone is given by,
$dW = V\;dq$
$dW =$ $ \frac{q}{C}$$.dq$ .......... $(ii)$ [∵ From equation $(i)$]
∴ The total workdone for passing the total charge $Q$ is given by,
To discharge a capacitor through a resistor, let us consider a capacitor of capacitance $(C)$ is initially charged to a potential difference $V_{0}$ and charge $q_{0}$, then
$q_{0} = C V_{0}$ .......... (i)
Now, the charged capacitor is joined to a resistor of resistance $(R)$ in series as shown in figure.
Figure 1: Circuit diagram for discharging Capacitor
At a time $(t)$ after the discharging through $(C)$ has begun, let the $V_{C}$ is the potential across the capacitor and $q$ be the charge. If current $(I)$ flows through $R$, then we have
$V_{C} = V_{R}$ .......... (ii)
or, $\frac{q}{c}$ = $IR$
or, $\frac{q}{c}$ = $-\frac{dq}{dt}$$R$ [∵ $I$ = $-\frac{dq}{dt}$; '-$ve$' sign shows that $q$ decreases with increasing $t$]
Thus the discharging time constant may be defined as the time at which the charge on the capacitor during discharging becomes about 37 % of the initial charge.
Let us consider a capacitor of capacitance $(C)$ and a resistor of resistance $(R)$ are connected in a series with a potential $(V)$, as shown in the figure.
Figure 1: Circuit diagram for a charging Capacitor
Initially, there is no charge in the capacitor. i.e. at time $t = 0$, the charge in the capacitor $C$ is also zero.
After a time $(t)$ sec, the charge on a capacitor is $q$. Let the current in the circuit is $I$, with a potential difference across the capacitor is $V_{C}$, and the potential difference across the resistor is $V_{R}$. Then,
$V{_C}$ = $\frac{q}{c}$ $\;\;\;$ and $\;\;\;$ $V_{R}$ = $IR$
If $q_{0}$ is the maximum charge stored in the capacitor, then
$q_{0}$ = $CV$
From Figure, $V$ = $V_{C}$ + $V_{R}$ .......... (i)
or, $\frac{q_{0}}{C}$ = $\frac{q}{C}$ + $IR$
or, $\frac{q_{0}- q}{C}$ = $R$ $\frac{dq}{dt}$
or, $\frac{dq}{q_{0}- q}$ = $\frac{1}{RC}$$dt$ .......... (ii)
∴ The charging time constant (or $R-C$ time constant) of a capacitor is defined as the time interval in which the capacitor charges by about $63 \%$ of its maximum charge.