Answers for "dates: add or subtract a month"

0

dates: add or subtract a month

require "date"

# Create a date
d = Date.new(2021, 5, 31)

# Subtract one month
subtract = d << 1

# Add one month
add = d >> 1

# Display values.
puts subtract   # it didn't just adjust the month
puts d          # base date
puts add        # days are adjusted to get actual end of month
Posted by: Guest on June-04-2021

Browse Popular Code Answers by Language