There are OpenmrsUtil.compareWithNullAsEarliest/Latest methods that are null-safe, and also handle both Date and Timestamp (which you sometimes get back as part of a Hibernate object). I suggest using this.