Mysql From_unixtime and UNIX_TIMESTAMP and DATE_FORMAT date functions

  • 2020-03-31 20:28:11
  • OfStack

From_unixtime () is a time function in MySQL
Date is an argument to be processed (which is a Unix timestamp), which can be a field name or can be a Unix timestamp string directly
The '%Y%m%d' that follows is mainly to format the return value
Such as:
Mysql> SELECT FROM_UNIXTIME(1249488000, '%Y%m%d')
- > 20071120
Mysql> SELECT FROM_UNIXTIME(1249488000, '%Y year %m month %d')
- > November 20, 2007
UNIX_TIMESTAMP() is the opposite of this

UNIX_TIMESTAMP (), UNIX_TIMESTAMP (date)

If no arguments are called, a Unix timestamp (seconds after '1970-01-01 00:00:00' GMT) is returned as an unsigned integer. If you call UNIX_TIMESTAMP() with date, it returns the parameter value as the number of seconds after '1970-01-01 00:00:00' GMT. A date can be a date string, a DATETIME string, a TIMESTAMP, or a local time number in YYMMDD or YYYMMDD format.

Such as:
 
mysql> SELECT UNIX_TIMESTAMP() ;  Execution makes time :2009-08-06 10:10:40 )  
->1249524739 
mysql> SELECT UNIX_TIMESTAMP('2009-08-06') ; 
->1249488000 

SELECT * 
FROM `student` 
WHERE regTime > UNIX_TIMESTAMP( curdate( ) ) //All students are registered today.

Related articles: