Forum: Ruby on Rails Seperate Date and Time strings into DateTime format

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.
Ruby on Rails: Talk (Guest)
on 2008-12-26 22:01
(Received via mailing list)
Hi

I have a database with a seperate Date and Time fields.

I'm trying to work out how to search, return and combine the two,
turning them into one DateTime value so that I can then compare it to
the current date and time and see if it's in the future or past.
However, I'm having no luck unfortunately.

Can anyone point me in the right direction?

I've searched for hours for this and having no real luck.

Thanks in advance
Ruby on Rails: Talk (Guest)
on 2008-12-26 22:08
(Received via mailing list)
Probably not the most elegant of solutions (and please let me know if
there are any better) but this is the best I have come up with!

dt = DateTime.parse("#{tapp.appdate}T#{tapp.apptime.strftime("%H:%M:
00")}")

On Dec 26, 8:00 pm, "Ruby on Rails: Talk" <removed_email_address@domain.invalid>
Dejan D. (Guest)
on 2008-12-27 00:06
(Received via mailing list)
Databases usually have a Date and Time set of functions and you can
use them to combine this two parts in one DateTime.

As suggested you can always use DateTime.strptime or Time.parse and
Time.to_datetime or any other way of string to DateTime
transformation.
You should ask your self do you need to make this transformation every
time you collect data from the table in question or you can make your
life a little easier with merging the two fields (Date and Time) in
one (DateTime).

There are a bunch of possibilities and the optimum one depends on your
overall usage of that data and plans for future usage.

On Dec 26, 9:08 pm, "Ruby on Rails: Talk" <removed_email_address@domain.invalid>
Ruby on Rails: Talk (Guest)
on 2008-12-27 00:41
(Received via mailing list)
Thanks for your response.

I need to keep the dates and times seperate really. It's for an
appointment system and it's easier if I keep things seperate at the
moment.
This topic is locked and can not be replied to.