Hi,
I am trying to do a subtraction of the date and time in the format
below with the current date and time
"2009-07-01 18:24:20"
Will I need to tokenise this string and do individual number
comparisons?
Thanks
Aidy
Hi,
I am trying to do a subtraction of the date and time in the format
below with the current date and time
"2009-07-01 18:24:20"
Will I need to tokenise this string and do individual number
comparisons?
Thanks
Aidy
aidy wrote:
Hi,
I am trying to do a subtraction of the date and time in the format
below with the current date and time"2009-07-01 18:24:20"
Will I need to tokenise this string and do individual number
comparisons?
irb(main):007:0> require 'time'
=> true
irb(main):009:0> t = Time.parse "2009-07-01 18:24:20"
=> Wed Jul 01 18:24:20 -0700 2009
irb(main):010:0> t.to_i
=> 1246497860
irb(main):011:0> t.day
=> 1
irb(main):012:0> t.hour
=> 18
See the Time class for details. You can also directly compare time objects (without using to_i to get seconds since the epoch):
irb(main):013:0> Time.now < Time.now
=> true
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
Joel VanderWerf wrote:
See the Time class for details. You can also directly compare time objects (without using to_i to get seconds since the epoch):
And you can also subtract Time objects to get seconds:
irb(main):016:0> t - Time.now
=> 27032.573318
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
Thanks Joel.
Aidy
On 1 July, 18:50, Joel VanderWerf <vj...@path.berkeley.edu> wrote:
irb(main):007:0> require 'time'
=> true
irb(main):009:0> t = Time.parse "2009-07-01 18:24:20"
=> Wed Jul 01 18:24:20 -0700 2009