Fix for datetime encoding

Critical bug in the datetime encoding fixed.