# Time.yesterday ? :)

**URL:** <https://rubytalk.org/t/time-yesterday/22552>\
**Category:** ruby-talk\
**Created:** [17 November 2005 15:57 UTC](https://rubytalk.org/t/time-yesterday/22552 "2005-11-17T15:57:25Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_Jurczuk](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Marcin\_Jurczuk](https://rubytalk.org/u/Marcin_Jurczuk)\
**Post date:** [17 November 2005 15:57 UTC](https://rubytalk.org/t/time-yesterday/22552/1 "2005-11-17T15:57:25Z")

</div>

Hello group.

Is there any simple method to get Time object like Time.now but with  
yesterday date, without worrying about end of month or begining new one ?

> **···**
>
> --  
> Spock ... Earth ..

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [17 November 2005 16:01 UTC](https://rubytalk.org/t/time-yesterday/22552/2 "2005-11-17T16:01:59Z")

</div>

Time.now - 86400

Kirk Haines

> **···**
>
> On Thursday 17 November 2005 8:57 am, Marcin Jurczuk wrote:
> 
> > Hello group.
> > 
> > Is there any simple method to get Time object like Time.now but with  
> > yesterday date, without worrying about end of month or begining new one ?

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@Michael\_Campbell](https://rubytalk.org/u/Michael_Campbell)\
**Post date:** [17 November 2005 23:17 UTC](https://rubytalk.org/t/time-yesterday/22552/3 "2005-11-17T23:17:18Z")

</div>

Marcin Jurczuk \<mj-usunto@tkb.pl\> writes:

> Hello group.
> 
> Is there any simple method to get Time object like Time.now but with  
> yesterday date, without worrying about end of month or begining new one ?

Pedantic to be sure, but keep in mind all the variations on the  
"... - 86400" scheme universally fail during the Daylight Savings  
Time cutovers that some of us are unfortunate to have to suffer.

Probably this won't affect you.

> **···**
>
> --  
> I tend to view "truly flexible" by another term: "Make everything  
> equally hard". -- DHH

---

<div class="post-metadata">

**Author:** ![Marcin\_Jurczuk](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Marcin\_Jurczuk](https://rubytalk.org/u/Marcin_Jurczuk)\
**Post date:** [17 November 2005 16:12 UTC](https://rubytalk.org/t/time-yesterday/22552/4 "2005-11-17T16:12:18Z")

</div>

Kirk Haines wrote:

> **···**
>
> > On Thursday 17 November 2005 8:57 am, Marcin Jurczuk wrote:
> > 
> > > Hello group.
> > > 
> > > Is there any simple method to get Time object like Time.now but with  
> > > yesterday date, without worrying about end of month or begining new one ?
> > 
> > Time.now - 86400
> > 
> > Kirk Haines
> 
> 😛  
> I knew that is something simple - but not so simple 🙂
> 
> Tha  
> --  
> Spock ... Earth ..

---

<div class="post-metadata">

**Author:** ![Reinder\_Verlinde](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@Reinder\_Verlinde](https://rubytalk.org/u/Reinder_Verlinde)\
**Post date:** [18 November 2005 00:07 UTC](https://rubytalk.org/t/time-yesterday/22552/5 "2005-11-18T00:07:18Z")

</div>

In article \<ufypux4u2.fsf@atlmicampbell.checkfree.com\>,

> **···**
>
> Michael Campbell \<michael.campbell@gmail.com\> wrote:
> 
> > Marcin Jurczuk \<mj-usunto@tkb.pl\> writes:
> > 
> > \> Hello group.  
> > \>  
> > \> Is there any simple method to get Time object like Time.now but with  
> > \> yesterday date, without worrying about end of month or begining new one ?
> > 
> > Pedantic to be sure, but keep in mind all the variations on the  
> > "... - 86400" scheme universally fail during the Daylight Savings  
> > Time cutovers that some of us are unfortunate to have to suffer.
> > 
> > Probably this won't affect you.
> 
> Even more pedantic: even if it does not, the assumption that every day  
> has 86400 seconds is still incorrect. A day with a leap second has 86401  
> or 86399 (has not happened yet) seconds.
> 
> Reinder

---

<div class="post-metadata">

**Author:** ![Greg\_Brown](https://avatars.discourse-cdn.com/v4/letter/g/e56c9b/32.png) [@Greg\_Brown](https://rubytalk.org/u/Greg_Brown)\
**Post date:** [17 November 2005 16:37 UTC](https://rubytalk.org/t/time-yesterday/22552/6 "2005-11-17T16:37:18Z")

</div>

greg@oracle ~ $ irb  
irb(main):001:0\> Time.now  
=\> Thu Nov 17 11:38:02 EST 2005  
irb(main):002:0\> class Time  
irb(main):003:1\> def self.yesterday  
irb(main):004:2\> now - 86400  
irb(main):005:2\> end  
irb(main):006:1\> end  
=\> nil  
irb(main):007:0\> Time.yesterday  
=\> Wed Nov 16 11:38:27 EST 2005

---

<div class="post-metadata">

**Author:** ![Marcin\_Mielzynski](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Marcin\_Mielzynski](https://rubytalk.org/u/Marcin_Mielzynski)\
**Post date:** [17 November 2005 16:37 UTC](https://rubytalk.org/t/time-yesterday/22552/7 "2005-11-17T16:37:18Z")

</div>

class Time  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def Time.yesterday  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t=Time.now  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time.at(t.to\_i-86400)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
end

p Time.yesterday

> I knew that is something simple - but not so simple 🙂
> 
> Tha

proste 😃

lopex

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@Michael\_Campbell](https://rubytalk.org/u/Michael_Campbell)\
**Post date:** [18 November 2005 16:03 UTC](https://rubytalk.org/t/time-yesterday/22552/8 "2005-11-18T16:03:19Z")

</div>

Reinder Verlinde \<reinder@verlinde.invalid\> writes:

> In article \<ufypux4u2.fsf@atlmicampbell.checkfree.com\>,
> 
> \> Marcin Jurczuk \<mj-usunto@tkb.pl\> writes:  
> \>  
> \> \> Hello group.  
> \> \>  
> \> \> Is there any simple method to get Time object like Time.now but with  
> \> \> yesterday date, without worrying about end of month or begining new one ?  
> \>  
> \> Pedantic to be sure, but keep in mind all the variations on the  
> \> "... - 86400" scheme universally fail during the Daylight Savings  
> \> Time cutovers that some of us are unfortunate to have to suffer.  
> \>  
> \> Probably this won't affect you.
> 
> Even more pedantic: even if it does not, the assumption that every  
> day has 86400 seconds is still incorrect. A day with a leap second  
> has 86401 or 86399 (has not happened yet) seconds.

\*Chuckle\* I completely forgot about that too; good catch. =)

> **···**
>
> > Michael Campbell \<michael.campbell@gmail.com\> wrote:
> 
> --  
> I tend to view "truly flexible" by another term: "Make everything  
> equally hard". -- DHH

---

<div class="post-metadata">

**Author:** ![Adam\_Sanderson](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@Adam\_Sanderson](https://rubytalk.org/u/Adam_Sanderson)\
**Post date:** [18 November 2005 16:27 UTC](https://rubytalk.org/t/time-yesterday/22552/9 "2005-11-18T16:27:22Z")

</div>

Well... if a time wasn't essential, and a Date could be used instead:  
&nbsp;&nbsp;require 'date'  
&nbsp;&nbsp;Date.today - 1

By the way, for anyone playing with date/time functions, date also will  
increment/decrement months:  
&nbsp;&nbsp;Date.today \>\> 1 # Adds a month  
&nbsp;&nbsp;Date.today \<\< 1 # Subtracts a month

Might be handy,  
&nbsp;&nbsp;.adam

---

<div class="post-metadata">

**Author:** ![Pete1](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@Pete1](https://rubytalk.org/u/Pete1)\
**Post date:** [17 November 2005 16:41 UTC](https://rubytalk.org/t/time-yesterday/22552/10 "2005-11-17T16:41:13Z")

</div>

even shorter:

def Time.yesterday; now - 86400; end

> **···**
>
> > --- Ursprüngliche Nachricht ---  
> > Von: "Greg Brown" \<greg7224@gmail.com\>  
> > An: ruby-talk@ruby-lang.org (ruby-talk ML)  
> > Betreff: Re: Time.yesterday ? 🙂  
> > Datum: Fri, 18 Nov 2005 01:37:18 +0900
> > 
> > greg@oracle ~ $ irb  
> > irb(main):001:0\> Time.now  
> > =\> Thu Nov 17 11:38:02 EST 2005  
> > irb(main):002:0\> class Time  
> > irb(main):003:1\> def self.yesterday  
> > irb(main):004:2\> now - 86400  
> > irb(main):005:2\> end  
> > irb(main):006:1\> end  
> > =\> nil  
> > irb(main):007:0\> Time.yesterday  
> > =\> Wed Nov 16 11:38:27 EST 2005

---

<div class="post-metadata">

**Author:** ![Greg\_Brown1](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@Greg\_Brown1](https://rubytalk.org/u/Greg_Brown1)\
**Post date:** [17 November 2005 16:52 UTC](https://rubytalk.org/t/time-yesterday/22552/11 "2005-11-17T16:52:17Z")

</div>

You don't need the intermediate variable

class Time  
&nbsp;&nbsp;def self.yesterday  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;now - 86400  
&nbsp;&nbsp;end  
end

Time.yesterday works just fine 🙂

---

<div class="post-metadata">

**Author:** ![Jacek1](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@Jacek1](https://rubytalk.org/u/Jacek1)\
**Post date:** [17 November 2005 19:12 UTC](https://rubytalk.org/t/time-yesterday/22552/12 "2005-11-17T19:12:18Z")

</div>

Marcin Mielżyński napisał(a):

> class Time  
> &nbsp;&nbsp;&nbsp;&nbsp;def Time.yesterday  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t=Time.now  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time.at(t.to\_i-86400)  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> end
> 
> p Time.yesterday
> 
> > I knew that is something simple - but not so simple 🙂
> > 
> > Tha
> 
> proste 😃
> 
> lopex

like a stick 🙂

---

<div class="post-metadata">

**Author:** ![Greg\_Brown1](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@Greg\_Brown1](https://rubytalk.org/u/Greg_Brown1)\
**Post date:** [17 November 2005 17:07 UTC](https://rubytalk.org/t/time-yesterday/22552/13 "2005-11-17T17:07:18Z")

</div>

Peter Ertl wrote:

> def Time.yesterday; now - 86400; end

Haha very nice.

---

<div class="post-metadata">

**Author:** ![Gene\_Tani](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@Gene\_Tani](https://rubytalk.org/u/Gene_Tani)\
**Post date:** [17 November 2005 18:57 UTC](https://rubytalk.org/t/time-yesterday/22552/14 "2005-11-17T18:57:18Z")

</div>

It's in Active Support:

[http://as.rubyonrails.com/](http://as.rubyonrails.com/)

Gregory Brown wrote:

> **···**
>
> > You don't need the intermediate variable
> > 
> > class Time  
> > &nbsp;&nbsp;def self.yesterday  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;now - 86400  
> > &nbsp;&nbsp;end  
> > end
> > 
> > Time.yesterday works just fine 🙂

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [17 November 2005 19:13 UTC](https://rubytalk.org/t/time-yesterday/22552/15 "2005-11-17T19:13:21Z")

</div>

No, Time.yesterday is not in active\_support, Time#yesterday is.

Also, active\_support emits far, far, far too many warnings. I could \*maybe\* deal with 1 or two warnings, but not 169:

$ cat yesterday.rb  
#!/usr/local/bin/ruby -w

require 'rubygems'  
require 'active\_support'

p Time.yesterday

$ ruby yesterday.rb  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active\_support/class\_inheritable\_attributes.rb:116: warning: discarding old inherited  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active\_support/inflections.rb:2: warning: ambiguous first argument; put parentheses or even spaces  
[snip 167 lines of warnings]  
yesterday.rb:6: undefined method `yesterday' for Time:Class (NoMethodError)

> **···**
>
> On Nov 17, 2005, at 10:57 AM, Gene Tani wrote:
> 
> > Gregory Brown wrote:
> > 
> > > You don't need the intermediate variable
> > > 
> > > class Time  
> > > &nbsp;&nbsp;def self.yesterday  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;now - 86400  
> > > &nbsp;&nbsp;end  
> > > end
> > > 
> > > Time.yesterday works just fine 🙂
> > 
> > It's in Active Support:
> > 
> > [http://as.rubyonrails.com/](http://as.rubyonrails.com/)
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![Gary\_Wright](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@Gary\_Wright](https://rubytalk.org/u/Gary_Wright)\
**Post date:** [17 November 2005 22:41 UTC](https://rubytalk.org/t/time-yesterday/22552/16 "2005-11-17T22:41:22Z")

</div>

Ditto. Whenever I see that sort of thing, I start to wonder  
what I'm getting myself into.

Gary Wright

> **···**
>
> On Nov 17, 2005, at 2:13 PM, Eric Hodel wrote:
> 
> > No, Time.yesterday is not in active\_support, Time#yesterday is.
> > 
> > Also, active\_support emits far, far, far too many warnings. I could \*maybe\* deal with 1 or two warnings, but not 169:
