Convert datetime to scalar value