How to get a time object from a date object?

lo there all, i have a date object, and i need to make a time object from
it.
i tried the to_i, ( what i really need are the seconds ) but it failed. I am
sure that there is an easy way to do this, i just can't seem to find it.

thanks
shawn

shawn bright wrote:

lo there all, i have a date object, and i need to make a time object from
it.
i tried the to_i, ( what i really need are the seconds ) but it failed. I am
sure that there is an easy way to do this, i just can't seem to find it.

Time.local(date.year, date.month, date.day)

(Courtesy of http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Conversions.html, actually.)

cool thanks. all working now

shawn

ยทยทยท

On 1/6/07, Devin Mullins <twifkak@comcast.net> wrote:

shawn bright wrote:
> lo there all, i have a date object, and i need to make a time object
from
> it.
> i tried the to_i, ( what i really need are the seconds ) but it failed.
> I am
> sure that there is an easy way to do this, i just can't seem to find it.

Time.local(date.year, date.month, date.day)

(Courtesy of

http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Conversions.html
,
actually.)

Devin Mullins wrote:

shawn bright wrote:
> lo there all, i have a date object, and i need to make a time object from
> it.
> i tried the to_i, ( what i really need are the seconds ) but it failed.
> I am
> sure that there is an easy way to do this, i just can't seem to find it.

Time.local(date.year, date.month, date.day)

(Courtesy of
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Conversions.html,
actually.)

class DateTime
  def to_time
    Time.local( year, month, day, hour, min, sec )
  end
end

puts (DateTime.now - 14).to_time

Devin Mullins wrote:

shawn bright wrote:
> lo there all, i have a date object, and i need to make a time object from
> it.
> i tried the to_i, ( what i really need are the seconds ) but it failed.
> I am
> sure that there is an easy way to do this, i just can't seem to find it.

Time.local(date.year, date.month, date.day)

(Courtesy of
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Conversions.html,
actually.)

class DateTime
  def to_time
    Time.local( year, month, day, hour, min, sec )
  end
end

puts (DateTime.now - 14).to_time