Fix casting datetime to long