What you're saying is - "If NEITHER datefrom1 NOR dateto1 are empty, reformat them and pass these values on to datefrom and dateto. However, if ANY are empty, pass both raw values (without reformatting) on to datefrom and dateto"
That makes little sense to me, but there again I have no idea about the input data or their format. You didn't share that information.
OK, so you seem to be using some DB abstraction class - no mention of what - is it from CI, Laravel or some other framework?
$datecondition is a variable - what's it doing there? If you want to add a 'where' filter/clause then I would assume you need to use something like...
I can't see how any of this would work or would filter your results, hence yoyu get the full whack of records.