db: Empty dates should be returned as null by typecast

If a date value is an empty string (''), the typecast should return null because e.g. pgsql dismiss empty strings. Swapping the if statements does this.

Please review!

Thanks
Sascha