Hi When returning data from a database column set as a date field I get ''2006-06-06'' I am then have these two lines of code in my controller, taht gain the date I require. pNow = Time.now @pDate = Time.local(pNow.year, pNow.month, 1) At the monment one is set to a date data type while one is set to a Time data type. how can i change these to be the same data type so i can run a > if statment on both of them to compare whats greater than the other? thanks scott -- Posted via http://www.ruby-forum.com/.
dont worry, found a Date class hidden away in the documentation problem solved by doing @pDate = Date.new(pTime.year, pTime.month, pTime.day) -- Posted via http://www.ruby-forum.com/.
Both Time and Date have methods to convert them into instances of the other, to_date and to_time respectively. Time.now.to_date Date.today.to_time -Jonathan. On 6/12/06, scott <scott@na.com> wrote:> dont worry, found a Date class hidden away in the documentation > > problem solved by doing @pDate = Date.new(pTime.year, pTime.month, > pTime.day) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
scott wrote:> At the monment one is set to a date data type > while one is set to a Time data type. > > how can i change these to be the same data > type so i can run a > if statment on both of them > to compare whats greater than the other?I think you''ll find what you need in the ActiveSupport::CoreExtensions::(Time | Date)::Conversions modules at http://api.rubyonrails.org/ hth, Bill