joe_c
(joe c.)
1
consider this code stub
require 'date'
today = DateTime.now
puts "Datetime.now returned: "+today.to_s
birthday = Date.new(2011, 10, 10)
days_to_go = today-birthday
puts "Days to go: "+days_to_go.to_s
It prints a number like -52632699/21600000
How do I get it to show true number of days, i.e. a number like 25
Thanks in advance!
Joe
···
--
Posted via http://www.ruby-forum.com/.
require 'date'
#today = DateTime.now
DateTime.now.to_date
birthday = Date.new(2011, 10, 10)
# days_to_go = today-birthday
days_to_go = birthday - today # the future is built with bigger numbers 
puts "Days to go: "+days_to_go.to_s
It prints a number like -52632699/21600000
puts days_to_go.class #=> Rational
How do I get it to show true number of days, i.e. a number like 25
puts "Days to go: #{days_to_go.to_i}"
HTH,
···
On Thu, Sep 15, 2011 at 8:16 AM, joe c. <joec54@gmail.com> wrote:
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
joe_c
(joe c.)
3
that works fine - thanks!
Joe
···
--
Posted via http://www.ruby-forum.com/.