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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e451d7-44b0c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e451d7-44b0c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?