lo there all,
i am wrestling with this for a bit now. how do i get a time object for two
weeks ago ?
if
t = Time.now, how do i get t - 2 weeks ?
thanks
lo there all,
i am wrestling with this for a bit now. how do i get a time object for two
weeks ago ?
if
t = Time.now, how do i get t - 2 weeks ?
thanks
shawn bright wrote:
lo there all,
i am wrestling with this for a bit now. how do i get a time object for two
weeks ago ?
if
t = Time.now, how do i get t - 2 weeks ?thanks
Time is stored in seconds so:
Time.now - 60*60*24*14 = 2 weeks ago
Dan
shawn bright wrote:
lo there all,
i am wrestling with this for a bit now. how do i get a time object for two
weeks ago ?
if
t = Time.now, how do i get t - 2 weeks ?thanks
If you use rails or include active support:
require 'rubygems'
require 'active_support'
2.weeks.ago
Dan
Hi,
You could check out chronic[1] as well - maybe it is an overkill for this single case, but if you have more queries like this, take a look for sure. It handles even much more complicated things like
last friday at 20:00
afternoon yesterday
etc.
Cheers,
Peter
[1] http://chronic.rubyforge.org/
thanks much, working all better now.
shawn
On 1/6/07, Dan Fitzpatrick <dan@eparklabs.com> wrote:
shawn bright wrote:
> lo there all,
>
> i am wrestling with this for a bit now. how do i get a time object for
> two
> weeks ago ?
> if
> t = Time.now, how do i get t - 2 weeks ?
>
> thanks
>
If you use rails or include active support:require 'rubygems'
require 'active_support'
2.weeks.agoDan
Dan Fitzpatrick wrote:
shawn bright wrote:
> lo there all,
>
> i am wrestling with this for a bit now. how do i get a time object for
> two
> weeks ago ?
> if
> t = Time.now, how do i get t - 2 weeks ?
>
> thanks
>
Time is stored in seconds so:Time.now - 60*60*24*14 = 2 weeks ago
Dan
class DateTime
def to_time
Time.local( *strftime( "%Y,%m,%d,%H,%M,%S" ).split( "," ).
map{|str| str.to_i } )
end
end
puts (DateTime.now - 14).to_time
William James wrote:
Dan Fitzpatrick wrote:
> shawn bright wrote:
> > lo there all,
> >
> > i am wrestling with this for a bit now. how do i get a time object for
> > two
> > weeks ago ?
> > if
> > t = Time.now, how do i get t - 2 weeks ?
> >
> > thanks
> >
> Time is stored in seconds so:
>
> Time.now - 60*60*24*14 = 2 weeks ago
>
> Danclass DateTime
def to_time
Time.local( *strftime( "%Y,%m,%d,%H,%M,%S" ).split( "," ).
map{|str| str.to_i } )
end
endputs (DateTime.now - 14).to_time
class DateTime
def to_time
Time.local( *strftime( "%Y %m %d %H %M %S" ).split )
end
end
puts (DateTime.now - 14).to_time