Forum: Ruby on Rails Convert Date to DateTime

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F677fa685a2cfe8aff31f161062db3d3?d=identicon&s=25 David (Guest)
on 2009-06-02 01:45
(Received via mailing list)
The method I am using to convert Date objects to DateTime objects is:

date_obj = DateTime.parse(Date.to_s)

Is this an okay way to go about doing this?  Or is there a more
efficient way?
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2009-06-02 01:55
(Received via mailing list)
On Mon, Jun 1, 2009 at 7:44 PM, David <dlynam@gmail.com> wrote:
>
> The method I am using to convert Date objects to DateTime objects is:
>
> date_obj = DateTime.parse(Date.to_s)
>
> Is this an okay way to go about doing this?  Or is there a more
> efficient way?

Well, on Rails you can do

date_obj.to_date_time

It's part of ActiveSupport

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
4a361ef7bd2a77d23db2a12363ee3347?d=identicon&s=25 cash22 (Guest)
on 2012-10-10 22:38
(Received via mailing list)
I think it's date_obj.to_datetime
This topic is locked and can not be replied to.