Yes you can - in perfect conditions this is one way of measuring gain. In the real world there are lots of confounding factors.
The formula you have looks correct. It could be simplified to $20\log(...)$ without the $()^2$ if you like. Distance must be in metres.
Field strength is related to power density by the following:
$P_d = {E^2}/377$
So if you know the field strength you can work out the power density at that position.
Power density is simply the Effective Radiated Power of the antenna divided by the area of a sphere, so
$P_d = {EiRP}/{4\pi r^2} $
And EiRP is just Power * Gain (in that direction, in linear units, isotropic)
Caveats:
This is all only useful in free space. So for measuring a dipole in the 70 cm band, mounted several metres away from conducting objects, it might work OK, you can expect about ±2 dB accuracy. It won't work for an HF dipole with the field strength meter some distance away, because the second formula is not true when there are reflecting and absorbing objects nearby. The field strength could vary by 10 or even 20 dB from what you expect in free space. In this case you are much better off trying to compare the field strength of two similar antennas.
It also only works in the pattern far field, approximately from a distance of $2D^2/\lambda$ where D is the maximum dimension of the antenna. Before this, the field strength is lower as the beam has not yet formed. This means for a yagi or a dish antenna you might have to be quite far away.