Elegantly check if a given date is yesterday

Aistina picture Aistina · Jul 9, 2010 · Viewed 10.5k times · Source

Assuming you have a Unix timestamp, what would be an easy and/or elegant way to check if that timestamp was some time yesterday?

I am mostly looking for solutions in Javascript, PHP or C#, but pseudo code and language agnostic solutions (if any) are welcome as well.

Answer

Omer Mor picture Omer Mor · Jul 9, 2010

In C# you could use this:

bool isYesterday = DateTime.Today - time.Date == TimeSpan.FromDays(1);