MySQL UNIX_TIMESTAMP is one of the Date Functions, which returns the seconds from 1970-00-00 00:00:00 UTC. This method accepts the date in YYMMDD, YYYYMMDD, YYMMDDHHMMSS, or YYYYMMDDHHMMSS formats.
Let us see how to use this UNIX_TIMESTAMP function to get the seconds from 1970 to Date with an example.
MySQL UNIX_TIMESTAMP Syntax
The basic syntax of the MySQL UNIX_TIMESTAMP Function is as shown below:
UNIX_TIMESTAMP();
UNIX_TIMESTAMP(date);
If you used the Date argument and specified any Date value. Then this method returns the seconds from 1970-00-00 00:00:00 to the user given date.
MySQL UNIX_TIMESTAMP function Example
The following examples help you understand the use of the Unix Timestamp method. Here, we are returning the Seconds from 1970 to the different dates.
SELECT UNIX_TIMESTAMP();
SELECT UNIX_TIMESTAMP(NOW());
SELECT UNIX_TIMESTAMP('2019-02-25');
UNIX TIMESTAMP Example 2
Let us see another example of this method. Here, we are using NOW, CURDATE, along with some additional operations inside this method. It means we are using MySQL DateTime in String format.
SELECT UNIX_TIMESTAMP(NOW() + 20);
SELECT UNIX_TIMESTAMP(CURDATE() + 2);
SELECT UNIX_TIMESTAMP('2018-12-31 23:59:59');
Let us see another Date Function example of the Unix Timestamp.
SELECT UNIX_TIMESTAMP('20181231');
SELECT UNIX_TIMESTAMP('20181231235959');