Open In App

UNIX_TIMESTAMP() function in MySQL

UNIX_TIMESTAMP() :
This function in MySQL helps to return a Unix timestamp. We can define a Unix timestamp as the number of seconds that have passed since ‘1970-01-01 00:00:00’UTC. Even if you pass the current date/time or another specified date/time, the function will return a Unix timestamp based on that.

Syntax :



UNIX_TIMESTAMP()
UNIX_TIMESTAMP(date)

Parameters :
It will accept only one argument.

Return :



Example-1 :
Working of UNIX_TIMESTAMP() using Current date/time.

SELECT UNIX_TIMESTAMP() 
As TimeStamp; 

Output :

TimeStamp
1606925233

Example-2 :
Working of UNIX_TIMESTAMP() using date value ‘1999-01-22’.

SELECT UNIX_TIMESTAMP('1999-01-22') 
As TimeStamp; 

Output :

TimeStamp
916988400

Example-3 :
Working of UNIX_TIMESTAMP() using DateTime value ‘2020-10-17 02:35:43’.

SELECT UNIX_TIMESTAMP('2020-10-17 02:35:43') 
As TimeStamp; 

Output :

TimeStamp
1602923743

Example-4 :
Working of UNIX_TIMESTAMP() using DateTime value along with fractional seconds ‘2020-10-17 02:35:43.12345’.

SELECT UNIX_TIMESTAMP('2020-10-17 02:35:43.12345') 
As TimeStamp; 

Output :

TimeStamp
1602923743.12345
Article Tags :
SQL