Ruby on Rails: Talk
2008-Dec-26 20:00 UTC
Seperate Date and Time strings into DateTime format
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ruby on Rails: Talk
2008-Dec-26 20:08 UTC
Re: Seperate Date and Time strings into DateTime format
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" <dazzaroo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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" <dazzaroo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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" <dazzaroo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ruby on Rails: Talk
2008-Dec-26 22:41 UTC
Re: Seperate Date and Time strings into DateTime format
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. On Dec 26, 10:05 pm, Dejan Dimic <dejan.di...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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" <dazzaroo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > 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" <dazzaroo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---