Quantcast
Channel: Convert Ruby Date to Integer - Stack Overflow
Browsing latest articles
Browse All 7 View Live

Answer by Pelle for Convert Ruby Date to Integer

I'm incredibly surprised that nobody has given what I believe to be the most correct answer to this.Since Ruby 1.9.3, Dates can be converted from and to integers. To get the julian day number for any...

View Article



Answer by Wagner Braga for Convert Ruby Date to Integer

I had to do it recently and took some time to figure it out but that is how I came across a solution and it may give you some ideas:require 'date'today = Date.todayyear = today.yearmonth = today.monday...

View Article

Answer by user9153631 for Convert Ruby Date to Integer

Date cannot directly become an integer. Ex:$ Date.today=> #<Date: 2017-12-29 ((2458117j,0s,0n),+0s,2299161j)>$ Date.today.to_i=> NoMethodError: undefined method 'to_i' for #<Date:...

View Article

Answer by Nowaker for Convert Ruby Date to Integer

Solution for Ruby 1.8 when you have an arbitrary DateTime object:1.8.7-p374 :001 > require 'date' => true 1.8.7-p374 :002 > DateTime.new(2012, 1, 15).strftime('%s') => "1326585600"

View Article

Answer by EnabrenTane for Convert Ruby Date to Integer

Time.now.to_ireturns seconds since epoch format

View Article


Answer by Phrogz for Convert Ruby Date to Integer

t = Time.now# => 2010-12-20 11:20:31 -0700# Seconds since epocht.to_i#=> 1292869231require 'date'd = Date.today#=> #<Date: 2010-12-20 (4911101/2,0,2299161)>epoch =...

View Article

Convert Ruby Date to Integer

How can I convert a Ruby Date to an integer?

View Article
Browsing latest articles
Browse All 7 View Live




Latest Images