---
title: "Date Shifting in Ruby"
description: "Using the and operators on Ruby Date objects. Practical notes and code examples on Date Shifting in Ruby by Hemanth HM in JS."
url: "https://h3manth.com/scribe/date-shifting-in-ruby/"
canonical_url: "https://h3manth.com/scribe/date-shifting-in-ruby/"
markdown_url: "https://h3manth.com/scribe/blog/date-shifting-in-ruby.md"
publishDate: "2014-09-11T00:00:00.000Z"
author: "Hemanth HM"
category: "ruby"
tags: ["ruby"]
word_count: 63
reading_time_minutes: 1
x_markdown_tokens: 190
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Date Shifting in Ruby

> Using the and operators on Ruby Date objects. Practical notes and code examples on Date Shifting in Ruby by Hemanth HM in JS.

Ruby has a hidden gem: the `<<` shift operator on Date objects!

```ruby
require 'date'
today = Date.today  # 2014-09-14

# Shift to previous month
last_month = today << 1
last_month.strftime('%B')  # "August"

# Shift to next months
next_month = today >> 2
next_month.strftime('%A-%B-%Y')  # "Friday-November-2014"

# Works on new dates too
Date.new(1988, 02, 01) >> 1  # 1988-03-01
```

Happy hacking! 🗓️
