Why do you need to do it in the query? Why not just handle it in the java code.
for example:
From RandomThing
Where randomTime is not null and
randomTime >= :currentTimestamp and
randomTime <= :maxTimestamp
And then just set the parameters.