We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Keeping monthly billing dates from drifting
almirsarajcic
0 comments
Copy link
If a subscription starts on January 31, 2026, a one-month shift gives you February 28. Shift again from there and the next bill lands on March 28. Keep the original date and shift by the number of months since signup.
anchor = ~D[2026-01-31]
february = Date.shift(anchor, month: 1)
Date.shift(february, month: 1) #=> ~D[2026-03-28]
Date.shift(anchor, month: 2) #=> ~D[2026-03-31]
Date.shift/2 clamps the day to the last valid day of the target month. Using the original date each time keeps the 31st when the month has one.
copied to clipboard