Can I compare MysQL timestamp with datetime columns? is it bad? -
so, have table columns "abc" timestamp , "bcd" datetime.
if this:
select * mytable abc > bcd
is bad? , affect performance?
how compare in terms of performance?
yes, can compare datetime
timestamp
. it's not bad, aware of following:
remember although
datetime
,date
, ,timestamp
values can specified using same set of formats, types not have same range of values. example,timestamp
values cannot earlier1970 utc
or later'2038-01-19 03:14:07'
utc.this means date such
'1968-01-01'
, while legaldatetime
ordate
value, not validtimestamp
value , converted 0.
from mysql reference manual :: datetime, date, , timestamp types.
note how following test cases works fine:
create table t1 (d1 datetime, d2 timestamp); insert t1 values ('1968-01-01 00:00:00', '1980-01-01 00:00:00'); insert t1 values ('2040-01-01 00:00:00', '1980-01-01 00:00:00'); select * t1 d2 < d1; +---------------------+---------------------+ | d1 | d2 | +---------------------+---------------------+ | 2040-01-01 00:00:00 | 1980-01-01 00:00:00 | +---------------------+---------------------+ 1 row in set (0.00 sec) select * t1 d2 > d1; +---------------------+---------------------+ | d1 | d2 | +---------------------+---------------------+ | 1968-01-01 00:00:00 | 1980-01-01 00:00:00 | +---------------------+---------------------+ 1 row in set (0.00 sec) select * t1 d2 < '2040-01-01 00:00:00'; +---------------------+---------------------+ | d1 | d2 | +---------------------+---------------------+ | 1968-01-01 00:00:00 | 1980-01-01 00:00:00 | | 2040-01-01 00:00:00 | 1980-01-01 00:00:00 | +---------------------+---------------------+ 2 rows in set (0.00 sec) select * t1 d2 > '2040-01-01 00:00:00'; empty set (0.00 sec)
Comments
Post a Comment