Logo

Programming-Idioms

  • C++
  • Php

Idiom #115 Compare dates

Set boolean b to true if date d1 is strictly before date d2 ; false otherwise.

$d1 = new DateTime('January 25 2016');
$d2 = new DateTime('January 26 2016');

$b = $d1 < $d2;

d1 and d2 are instances of DateTime, which is directly comparable.
bool b = d1 < d2;

New implementation...
< >
programming-idioms.org