Is it legal to compare date / datetime / time / timestamp / etc using comparison operators ( greater than / less than / equals ) in MySQL? -


can point me official mysql documentation stated can comparisons this:

declare mydate date; ... if mydate > '2015-04-01'     ... end if; 

excerpt mysql reference

when compare date, time, datetime, or timestamp constant string <, <=, =, >=, >, or between operators, mysql converts string internal long integer faster comparison (and bit more “relaxed” string checking). however, conversion subject following exceptions:

  1. when compare 2 columns
  2. when compare date, time, datetime, or timestamp column expression
  3. when use comparison method other listed, such in or strcmp().

for exceptions, comparison done converting objects strings , performing string comparison. on safe side, assume strings compared strings , use appropriate string functions if want compare temporal value string. special “zero” date '0000-00-00' can stored , retrieved '0000-00-00'. when '0000-00-00' date used through connector/odbc, automatically converted null because odbc cannot handle kind of date. because mysql performs conversions described, following statements work (assume idate date column):

insert t1 (idate) values (19970505); insert t1 (idate) values ('19970505'); insert t1 (idate) values ('97-05-05'); insert t1 (idate) values ('1997.05.05'); insert t1 (idate) values ('1997 05 05'); insert t1 (idate) values ('0000-00-00');  select idate t1 idate >= '1997-05-05'; select idate t1 idate >= 19970505; select mod(idate,100) t1 idate >= 19970505; select idate t1 idate >= '19970505'; 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -