Why can mysql save time with varchar and still make time comparisons?

Why can mysql save time with varchar and still make time comparisons? What is the principle?

Y-m-d H:i:s like this


because strings can be compared in dictionary order. For example,

echo 'ABC' > 'ABB' ? 'true' : 'false'; // true
echo 'ABC' > 'ABD' ? 'true' : 'false'; // false

your date-time format causes the result of string comparison to be the same as that of date-time comparison.
if you change the format, such as jS M, Y , you will get a string like 1st Jan, 2018 , which may be useless for comparison.

Menu