Improved datetime conversion