At any given thermostat setting, for any given amount of time, it will be more efficient for your gas water heater to be turned off than to be turned on.
As described by Newton's law of cooling, the rate of heat loss of a body is proportional to the difference in temperatures between the body and its surroundings.
Comparing the two situations - heater on and heater off - we can disregard h (heat transfer rate, generally related to insulation of the tank), A (surface area of the device), and Tenv (temperature of the environment) as these should be roughly fixed. Thus only T (temperature of the water) will be interesting for the comparison. The greater T, the greater the heat loss, the greater the energy required by the heater.
If the heater is on, energy required is equal to energy lost which is proportional to T times the duration being measured. Notably, T is held more or less constant at its greatest value in this scenario.
If the heater is off, energy required is 0 plus the energy to return the water to the desired temperature. It should be clear that for a long enough period, the heater off situation always requires less energy because T is not even a factor.
What about for shorter durations? For the heater off scenario, the amount of energy required to return the water to the thermostat set temperature increases until the water temperature reaches the ambient temperature and then remains constant. However, since T is dropping the rate of that energy requirement increase is dropping as well. Therefore the average power (energy per time) required to re-obtain the thermostat set temperature is highest instantaneously after the heater is shut off (call it Time) and ever after smaller and smaller.
But the power required to re-obtain the thermostat set temperature at Time is exactly equal to the average power required by the heater on scenario for the entire time period.
Therefore shutting the heater off will always use less power, regardless of the duration.
There should be no practical matters which change this conclusion. The heat exchanger in the water heater is probably more efficient at lower water temperatures, making the heater off scenario even better. If the water heater has a gas pilot then that's more wasted energy in the heater on scenario. If it has an inefficient ignition system then that's still more benefit to the heater off scenario, which will involve fewer ignitions.