change the max and min function in order to support the datetime/time

Hello, please look at this,
I change the max and min function in order to support the datetime/time field.
Sorry I can only test in mysql, and it work.

thanks.