check for valid date before constructing query