Kat Kat - 27 days ago 8
Ruby Question

Ruby: how to Last day of last month

Please help me with the code i.e how to get Last day of Last month.

i.e. if today date is 06-11-2016 (dd-mm-yyyy) => output: 31-10-2016

Answer

Anything like this?

require 'date'

t = Date.today
Date.new(t.year, t.month) - 1
 => #<Date: 2016-10-31 ((2457693j,0s,0n),+0s,2299161j)> 
Comments