the type is integer like :

int(11) 

is good for indexing and conditions like > < =

Answer from Haim Evgi on Stack Overflow
🌐
DataCamp
datacamp.com › doc › mysql › mysql-unix-timestamp
MySQL UNIX_TIMESTAMP() Function: Usage & Examples
The `UNIX_TIMESTAMP()` function in MySQL returns the current Unix timestamp, which is the number of seconds that have elapsed since '1970-01-01 00:00:00' UTC.
Discussions

Correct Column Type For a Unix Timestamp with Microseconds
Why not use DATETIME? Then, you can use any of the built-in time functions or built-in time math features. With DECIMAL, INT, or BIGINT, you have to manage the conversion and math yourself, which is quite difficult. The perofrmance differences aren't something you're ever going to notice; the bugs you create by screwing up time math, or the extra work you create by doing conversions every single query -- well, you'll notice those on day one. More on reddit.com
🌐 r/mysql
11
2
August 2, 2021
database design - Store date as unix timestamp or TIMESTAMP data type in MySQL? - Stack Overflow
I need to store dates (with time) in a MySQL database. I want to be able to format these how I like. Then what is the best way to store dates in a MySQL database? The DATETIME type, the TIMESTAMP type or simply a unix timestamp in a numeric data type? More on stackoverflow.com
🌐 stackoverflow.com
php - How to store UNIX timestamps with MySQL - Stack Overflow
What field type should I store my unix timestamps as, currently I am using int(11) with a default of none. By extension... is there a way to store the current unix timestamp (e.g. 1475971200) by default in MySQL? More on stackoverflow.com
🌐 stackoverflow.com
sql - Is it possible to create a column with a UNIX_TIMESTAMP default in MySQL? - Stack Overflow
I'm trying to do this, but it seems like MySQL isn't allowing me. Is there a solution to this issue or am I expected to always include the function in my INSERT queries? CREATE TABLE foo( created INT NOT NULL DEFAULT UNIX_TIMESTAMP() ) I'm aware of the TIMESTAMP type that accepts a CURRENT_TIMESTAMP default, but my client insisted on using epoch time in the database... More on stackoverflow.com
🌐 stackoverflow.com
🌐
MySQL
dev.mysql.com › doc › refman › 8.0 › en › date-and-time-functions.html
MySQL :: MySQL 8.0 Reference Manual :: 14.7 Date and Time Functions
January 18, 2022 - When the date argument is a TIMESTAMP column, UNIX_TIMESTAMP() returns the internal timestamp value directly, with no implicit “string-to-Unix-timestamp” conversion. Prior to MySQL 8.0.28, the valid range of argument values is the same as for the TIMESTAMP data type: '1970-01-01 00:00:01.000000' UTC to '2038-01-19 03:14:07.999999' UTC.
🌐
TutorialsPoint
tutorialspoint.com › what-is-the-data-type-for-unix-timestamp-in-mysql
What is the data type for unix_timestamp in MySQL?
July 30, 2019 - The best data type for unix_timestamp in MySQL is integer. The integer data type is as follows int(11); The integer data type is useful for condition checking like ( > ,<= ) and indexing. The return
🌐
Reddit
reddit.com › r/mysql › correct column type for a unix timestamp with microseconds
r/mysql on Reddit: Correct Column Type For a Unix Timestamp with Microseconds
August 2, 2021 -

Hi,

Currently I have a column of type char that stores unix time with microseconds as follows:

 `last_update_utime` char(18) COLLATE utf8mb4_unicode_ci DEFAULT NULL 
  COMMENT 'Unix Time of Last Update with mseconds'

I update that column as below;

UPDATE `transaction_tbl` 

SET    `transaction_token` = '$token',
       `last_update_utime` = UNIX_TIMESTAMP(LOCALTIMESTAMP(6))

WHERE  `user_id` = '$userID'

I use the field last_update_utime to address concurrency.
What is the correct column type for unix timestamps with microseconds ?

i have seen posts on the web stating int(11) or bigint(20)
but the issue of microseconds is not addressed ?
Is keeping the column type to 'char' sufficient or better to use something like decimal(18,6) ?

Pls advise.

🌐
Scaler
scaler.com › home › topics › mysql unix_timestamp() function
MySQL UNIX_TIMESTAMP() Function - Scaler Topics
July 17, 2023 - The MySQL UNIX_TIMESTAMP() function is an inbuilt MySQL function that accepts only one argument which is either of a DATE or DATETIME data type and returns an unsigned integer which is the number of seconds passed since 1970-01-01 00:00:00 UTC.
🌐
w3resource
w3resource.com › mysql › date-and-time-functions › mysql-unix_timestamp-function.php
MySQL UNIX_TIMESTAMP() function - w3resource
3 weeks ago - MySQL UNIX_TIMESTAMP() returns a Unix timestamp in seconds since '1970-01-01 00:00:00' UTC as an unsigned integer if no arguments are passed with UNIT_TIMESTAMP().
Find elsewhere
🌐
MySQL
dev.mysql.com › doc › en › date-and-time-functions.html
MySQL :: MySQL 8.4 Reference Manual :: 14.7 Date and Time Functions
When the date argument is a TIMESTAMP column, UNIX_TIMESTAMP() returns the internal timestamp value directly, with no implicit “string-to-Unix-timestamp” conversion. The valid range of argument values is the same as for the TIMESTAMP data type: '1970-01-01 00:00:01.000000' UTC to '2038-01-19 ...
🌐
MariaDB
mariadb.com › kb › en › unix_timestamp
UNIX_TIMESTAMP | Server | MariaDB Documentation
If UNIX_TIMESTAMP() is called with a date argument, it returns the value of the argument as seconds since 1970-01-01 00:00:00 UTC. date may be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the format YYMMDD or YYYYMMDD.
🌐
Epoch Converter
epochconverter.com › epoch converter › programming a-z › using unix timestamps in mysql mini-course
Using Unix Timestamps in MySQL Mini-Course - Epoch Converter
INSERT INTO mytable VALUES(1,'pagename',UNIX_TIMESTAMP(now())) ... There's one big problem with MySQL: MySQL cannot convert negative epoch timestamps (dates before 1-1-1970). This creates problems with for example birthdates.
🌐
TutorialsPoint
tutorialspoint.com › mysql › mysql_date_time_functions_unix_timestamp.htm
MySQL - UNIX_TIMESTAMP() Function
The following query returns the unix timestamp in seconds as an unsigned integer since '1970-01-01 00:00:00' UTC − ... If we specify a date or datetime value before '1970-01-01 00:00:00' UTC to this function, it returns 0 as output − ... ...
Top answer
1 of 6
67

The way MySQL implements the TIMESTAMP data type, it is actually storing the epoch time in the database. So you could just use a TIMESTAMP column with a default of CURRENT_TIMESTAMP and apply the UNIX_TIMESTAMP() to it if you want to display it as an int:

CREATE TABLE foo(
  created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

insert into foo values (current_Date()),(now());

select unix_timestamp(created) from foo;
+-------------------------+
| unix_timestamp(created) |
+-------------------------+
|              1300248000 |
|              1300306959 |
+-------------------------+
2 rows in set (0.00 sec)

However, if you really want the datatype of the column to be INT, you can use R. Bemrose's suggestion and set it via trigger:

CREATE TABLE foo(
  created INT NULL
);

delimiter $$

create trigger tr_b_ins_foo before insert on foo for each row
begin
  if (new.created is null)
  then
    set new.created = unix_timestamp();
  end if;
end $$

delimiter ;


insert into foo values (unix_timestamp(current_Date())), (null);

select created from foo;
+------------+
| created    |
+------------+
| 1300248000 |
| 1300306995 |
+------------+
2 rows in set (0.00 sec)
2 of 6
20

From the documentation:

With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column.

🌐
MySQL
dev.mysql.com › doc › refman › 8.0 › en › datetime.html
MySQL :: MySQL 8.0 Reference Manual :: 13.2.2 The DATE, DATETIME, and TIMESTAMP Types
May 6, 2022 - The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD hh:mm:ss' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. The TIMESTAMP data type is used for values that contain both date ...
🌐
MySQL
dev.mysql.com › doc › refman › 8.0 › en › date-and-time-type-syntax.html
MySQL :: MySQL 8.0 Reference Manual :: 13.2.1 Date and Time Data Type Syntax
April 16, 2015 - MySQL permits fractional seconds for TIME, DATETIME, and TIMESTAMP values, with up to microseconds (6 digits) precision. To define a column that includes a fractional seconds part, use the syntax type_name(fsp), where type_name is TIME, DATETIME, or TIMESTAMP, and fsp is the fractional seconds precision.
🌐
Restack
restack.io › p › understanding-tinyint-vs-int-in-sql-answer-mysql-date-time-to-unix-timestamp
MySQL Date Time To Unix Timestamp | Restackio
May 3, 2025 - When storing Unix timestamps in MySQL, it is common to use the INT or BIGINT data types, depending on the range of timestamps you need to accommodate.