from_unixtime and unix_timestamp usage

from_unixtime and unix_timestamp are two functions used to convert timestamps in SQL.

1. from_unixtime function:

The from_unixtime function converts a Unix timestamp to a datetime format in MySQL or Hive. Its syntax is as follows:
from_unixtime(unix_timestamp, [format])
Parameter description:
unix_timestamp: indicates the Unix timestamp, that is, the number of seconds elapsed since January 1, 1970 (midnight in UTC/GMT).
format: Indicates the date and time format of the result, the default is YYYY-MM-DD HH:MM:SS format .
For example:

SELECT from_unixtime(1605256620);
The result is: 2020-11-13 09:30:20

2. unix_timestamp function:

The unix_timestamp function converts datetime format in MySQL or hive to Unix timestamp. Its syntax is as follows:

unix_timestamp([datetime], [format])
parameter description:
datetime: Indicates the date and time to be converted, which can be a time string or a date and time field.
format: Indicates the format of the date and time, the default is the YYYY-MM-DD HH:MM:SS format.
For example:
SELECT unix_timestamp('2020-11-13 09:30:20');
The result is : 1605256620

Guess you like

Origin blog.csdn.net/m0_49303490/article/details/131027556