scott
1
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
scott
2
dont worry, found a Date class hidden away in the documentation
problem solved by doing @pDate = Date.new(pTime.year, pTime.month,
pTime.day)
scott
3
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.
scott
4
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