unix_timestamp

Description

Syntax

INT UNIX_TIMESTAMP(), UNIX_TIMESTAMP(DATETIME date)

Converting a Date or Datetime type to a UNIX timestamp.

If there are no parameters, the current time is converted into a timestamp.

The parameter needs to be Date or Datetime type.

Any date before 1970-01-01 00:00:00 or after 2038-01-19 03:14:07 will return 0.

See date_format function to get Format explanation.

This function is affected by time zone.

example

  1. mysql> select unix_timestamp();
  2. +------------------+
  3. | unix_timestamp() |
  4. +------------------+
  5. | 1558589570 |
  6. +------------------+
  7. mysql> select unix_timestamp('2007-11-30 10:30:19');
  8. +---------------------------------------+
  9. | unix_timestamp('2007-11-30 10:30:19') |
  10. +---------------------------------------+
  11. | 1196389819 |
  12. +---------------------------------------+
  13. mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
  14. +---------------------------------------+
  15. | unix_timestamp('2007-11-30 10:30-19') |
  16. +---------------------------------------+
  17. | 1196389819 |
  18. +---------------------------------------+
  19. mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
  20. +---------------------------------------+
  21. | unix_timestamp('2007-11-30 10:30%3A19') |
  22. +---------------------------------------+
  23. | 1196389819 |
  24. +---------------------------------------+
  25. mysql> select unix_timestamp('1969-01-01 00:00:00');
  26. +---------------------------------------+
  27. | unix_timestamp('1969-01-01 00:00:00') |
  28. +---------------------------------------+
  29. | 0 |
  30. +---------------------------------------+

keywords

  1. UNIX_TIMESTAMP,UNIX,TIMESTAMP