Another variable that has a major influence on gamma, is how much time is left before the option expires. Even if all other things remain completely static, the simple passage of time will have an effect on the gamma of an option.
This chart shows the gamma of the $100 strike options based on where the underlying price is, with an IV of 40%, and various DTE.

As we can see, this chart is very similar to the one from the previous lecture that showed the effect of varying IV on gamma. Whether the passage of time leads to an increase or decrease in the gamma depends on where the underlying price is relative to the strike price.
When the underlying price is close to the strike price, so when the option is ATM or close to the money, the option’s gamma increases as time passes. If the option is still ATM as we come into expiration, gamma spikes dramatically, meaning any move in the underlying price will have a dramatic effect on the option’s delta.
Towards either side of the chart though, where the underlying price is far away from the strike price, we can see that as time passes the gamma reduces to close to zero. The further away the underlying price is, the sooner this happens.
Individual option views
Let’s now look at 5 different strike prices to further illustrate how the gamma evolves as time passes.
This chart shows the gamma of the $70, $85, $100, $115, and $130 strikes. The x axis shows the days to expiry, so as we move from left to right on the chart, we can see how the gamma for each of these strikes changes as time passes.

If we compare this gamma chart to a chart of the corresponding deltas for call options at those strikes, we can understand why we see these patterns. This is a chart of the corresponding call deltas. All parameters are exactly the same, except the delta is displayed instead of the gamma.
When we are getting close to expiry, the ITM call strikes of $70 and $85, both have a delta of close to one. For this to change, the underlying price would have to decrease dramatically, which with hardly any time remaining until the options expire, is unlikely. A $1 change in the underlying price will therefore barely affect their delta, so their gamma is very small.
Similarly the OTM call strikes of $115 and $130, both have a delta of close to zero. For this to change, the underlying price would have to increase dramatically, which with hardly any time remaining until the options expire, is also unlikely. A $1 change in the underlying price will therefore barely affect their delta, so their gamma is very small.
For the ATM strike of $100 though the picture is very different. Remember as the time to expiry approaches zero, the delta of ITM call options approaches one, and the delta of OTM call options approaches zero. The ATM strike of $100 could still easily be either, with a $1 change in the underlying price having a large impact on which is most likely with only a small amount of time left. A $1 change in the underlying price can therefore have a large impact on the delta of the option, so the gamma of the ATM strike is high as we come into expiration.
In summary
With less time remaining until expiry, there is less time for price to move. This means that large moves before expiration are less likely.
This leaves both ITM and OTM options with very little gamma, because it would take a very large price move to change their delta significantly.
For ATM options though, this leads to an increase in gamma. This is because with a small amount of time until expiry, even small changes in the underlying price have a large impact on the likelihood of the option expiring ITM or OTM.