UTC_TIMESTAMP()

Description

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 string or numeric context.

Syntax

  1. > UTC_TIMESTAMP, UTC_TIMESTAMP([fsp])

Arguments

ArgumentsDescription
fspOptional. If the fsp argument is given to specify a fractional seconds precision from 0 to 6, the return value includes a fractional seconds part of that many digits.

Examples

  • Example 1:
  1. mysql> SELECT UTC_TIMESTAMP();
  2. +---------------------+
  3. | utc_timestamp() |
  4. +---------------------+
  5. | 2022-09-16 03:37:40 |
  6. +---------------------+
  7. 1 row in set (0.01 sec)
  8. mysql> select unix_timestamp(utc_timestamp());
  9. +---------------------------------+
  10. | unix_timestamp(utc_timestamp()) |
  11. +---------------------------------+
  12. | 1663282842 |
  13. +---------------------------------+
  14. 1 row in set (0.02 sec)
  • Example 2:
  1. create table t1 (ts timestamp);
  2. set time_zone='+00:00';
  3. mysql> select unix_timestamp(utc_timestamp())-unix_timestamp(utc_timestamp());
  4. +-------------------------------------------------------------------+
  5. | unix_timestamp(utc_timestamp()) - unix_timestamp(utc_timestamp()) |
  6. +-------------------------------------------------------------------+
  7. | 0 |
  8. +-------------------------------------------------------------------+
  9. 1 row in set (0.00 sec)
  10. insert into t1 (ts) values ('2003-03-30 02:30:00');
  11. set time_zone='+10:30';
  12. mysql> select unix_timestamp(utc_timestamp())-unix_timestamp(utc_timestamp());
  13. +-------------------------------------------------------------------+
  14. | unix_timestamp(utc_timestamp()) - unix_timestamp(utc_timestamp()) |
  15. +-------------------------------------------------------------------+
  16. | 0 |
  17. +-------------------------------------------------------------------+
  18. 1 row in set (0.01 sec)
  19. insert into t1 (ts) values ('2003-03-30 02:30:00');
  20. set time_zone='-10:00';
  21. mysql> select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
  22. +-----------------------------------------------------------------------+
  23. | unix_timestamp(utc_timestamp()) - unix_timestamp(current_timestamp()) |
  24. +-----------------------------------------------------------------------+
  25. | 36000 |
  26. +-----------------------------------------------------------------------+
  27. 1 row in set (0.00 sec)
  28. insert into t1 (ts) values ('2003-03-30 02:30:00');
  29. mysql> select * from t1;
  30. +---------------------+
  31. | ts |
  32. +---------------------+
  33. | 2003-03-29 16:30:00 |
  34. | 2003-03-29 06:00:00 |
  35. | 2003-03-30 02:30:00 |
  36. +---------------------+
  37. 3 rows in set (0.00 sec)
  • Example 3:
  1. DROP TABLE IF EXISTS t1;
  2. CREATE TABLE t1 (a TIMESTAMP);
  3. INSERT INTO t1 select (utc_timestamp());
  4. INSERT INTO t1 select (utc_timestamp());
  5. INSERT INTO t1 select (utc_timestamp());
  6. mysql> SELECT year(a) FROM t1 WHERE a > '2008-01-01';
  7. +---------+
  8. | year(a) |
  9. +---------+
  10. | 2022 |
  11. | 2022 |
  12. | 2022 |
  13. +---------+
  14. 3 rows in set (0.04 sec)
  1. DROP TABLE if exists t1;
  2. create table t1 (a int primary key, b int, c int, d timestamp);
  3. insert into t1 select 1,1,1,utc_timestamp();
  4. insert into t1 select 2,0,0,null;
  5. mysql> select a,b,c,year(d) from t1;
  6. +------+------+------+---------+
  7. | a | b | c | year(d) |
  8. +------+------+------+---------+
  9. | 1 | 1 | 1 | 2022 |
  10. | 2 | 0 | 0 | NULL |
  11. +------+------+------+---------+
  12. 2 rows in set (0.01 sec)
  1. DROP TABLE if exists t1;
  2. CREATE TABLE t1 (a TIMESTAMP);
  3. INSERT INTO t1 select (utc_timestamp());
  4. INSERT INTO t1 select (utc_timestamp());
  5. mysql> SELECT 1 FROM t1 ORDER BY 1;
  6. +------+
  7. | 1 |
  8. +------+
  9. | 1 |
  10. | 1 |
  11. +------+
  12. 2 rows in set (0.01 sec)

Constraints

Operator + or - with parameters DATETIME BIGINT is not supported now.