Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #115 Compare dates

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

boolean b = d1.before(d2)
bool b = d1 < d2;
import std.datetime;
bool b = d1 < d2;
bool b = d1.isBefore(d2);
import "time"
b := d1.Before(d2)
import Data.Time.Calendar
b = d1 < d2
let b = d1 < d2
import java.util.Date;
boolean before = (d1.compareTo(d2) == -1);
$d1 = new DateTime('January 25 2016');
$d2 = new DateTime('January 26 2016');

$b = $d1 < $d2;
uses dateutils;
b := (CompareDateTime(d1,d2) = -1);
my $b = d1 < d2;
import datetime
b = d1 < d2
b = d1 < d2
extern crate chrono;
use chrono::prelude::*;
let b = d1 < d2;

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