UTC_TIMESTAMP() 对比。 CONCAT(UTC_DATE(), ' ', UTC_TIME())
UTC_TIMESTAMP() VS. CONCAT(UTC_DATE(), ' ', UTC_TIME())
UTC_TIMESTAMP ()
和 CONCAT (UTC_DATE (), '', UTC_TIME ())
功能相同吗?
编辑:
当我测试它时,UTC_TIMESTAMP()
没有 return UNIX TIMESTAMP。 (使用 MariaDB 10.x)
没有。 UTC_TIMESTAMP returns 一个字符串或数字,CONCAT returns 一个字符串。
UTC_TIMESTAMP, UTC_TIMESTAMP([fsp])
Returns the current UTC date and time as a value in 'YYYY-MM-DD
HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function
is used in a string or numeric context.
https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_utc-timestamp
https://mariadb.com/kb/en/library/utc_timestamp/
CONCAT(str1,str2,...)
Returns the string that results from concatenating the arguments.
https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat
https://mariadb.com/kb/en/library/concat/
create table test ( real_ts timestamp, fake_ts varchar(40));
✓
insert into test (real_ts, fake_ts)
values (utc_timestamp()+6, CONCAT (UTC_DATE (), '', UTC_TIME ()));
✓
select
*
from test;
real_ts | fake_ts
:------------------ | :-----------------
2017-11-09 06:57:15 | 2017-11-0906:57:09
insert into test (real_ts)
values (utc_timestamp()+6)
;
✓
insert into test (real_ts)
values ( CONCAT (UTC_DATE (), '', UTC_TIME ())+6)
;
Truncated incorrect DOUBLE value: '2017-11-0906:57:09'
dbfiddle here
我不会相信CONCAT
(即使它会起作用)。如果实现在午夜之前调用 UTC_DATE()
并在午夜之后调用 UTC_TIME()
怎么办?哎呀,组合串掉了一整天!
UTC_TIMESTAMP ()
和 CONCAT (UTC_DATE (), '', UTC_TIME ())
功能相同吗?
编辑:
当我测试它时,UTC_TIMESTAMP()
没有 return UNIX TIMESTAMP。 (使用 MariaDB 10.x)
没有。 UTC_TIMESTAMP returns 一个字符串或数字,CONCAT returns 一个字符串。
UTC_TIMESTAMP, UTC_TIMESTAMP([fsp])
Returns the current UTC date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_utc-timestamp
https://mariadb.com/kb/en/library/utc_timestamp/
CONCAT(str1,str2,...)
Returns the string that results from concatenating the arguments. https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat
https://mariadb.com/kb/en/library/concat/
create table test ( real_ts timestamp, fake_ts varchar(40));
✓
insert into test (real_ts, fake_ts) values (utc_timestamp()+6, CONCAT (UTC_DATE (), '', UTC_TIME ()));
✓
select * from test;
real_ts | fake_ts :------------------ | :----------------- 2017-11-09 06:57:15 | 2017-11-0906:57:09
insert into test (real_ts) values (utc_timestamp()+6) ;
✓
insert into test (real_ts) values ( CONCAT (UTC_DATE (), '', UTC_TIME ())+6) ;
Truncated incorrect DOUBLE value: '2017-11-0906:57:09'
dbfiddle here
我不会相信CONCAT
(即使它会起作用)。如果实现在午夜之前调用 UTC_DATE()
并在午夜之后调用 UTC_TIME()
怎么办?哎呀,组合串掉了一整天!