Kat Kat - 1 year ago 85
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 Source

Anything like this?

require 'date'

t = Date.today
Date.new(t.year, t.month) - 1
 => #<Date: 2016-10-31 ((2457693j,0s,0n),+0s,2299161j)> 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download