©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The FROM_UNIXTIME SQL Function in MySQL and MariaDB - Format Unix timestamp

FROM_UNIXTIMESyntax:FROM_UNIXTIME(Unix timestamp [, Format])
Return value:DATETIME
Function type:Date and Time function
Function Description

The FROM_UNIXTIME() function returns the argument "Unix timestamp" as a value in the format YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuuuuu.

The type of return value depends on whether the function is used in a string or numeric context.

The return value is returned expressed in the current time zone.

The value of "Unix timestamp" is an internal timestamp value as produced by the UNIX_TIMESTAMP() function.

It should be noted that the function calculates with a UTC date and the result varies depending on the time zone. See example.

If the value of "Unix timestamp" is invalid or NULL, or "Format" is NULL, the FROM_UNIXTIME() function returns NULL.


If the argument "Format" is given, the result will be formatted according to the format string.

Options for the "Format" string:

OptionDescription
%aShort weekday name in current locale (Variable lc_time_names).
%bShort form month name in current locale. For locale en_US this is one of: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov or Dec.
%cMonth with 1 or 2 digits.
%DDay with English suffix 'th', 'nd', 'st' or 'rd''. (1st, 2nd, 3rd...).
%dDay with 2 digits.
%eDay with 1 or 2 digits.
%fMicroseconds 6 digits.
%HHour with 2 digits between 00-23.
%hHour with 2 digits between 01-12.
%IHour with 2 digits between 01-12.
%iMinute with 2 digits.
%jDay of the year (001-366)
%kHour with 1 digits between 0-23.
%lHour with 1 digits between 1-12.
%MFull month name in current locale (Variable lc_time_names).
%mMonth with 2 digits.
%pAM/PM according to current locale (Variable lc_time_names).
%rTime in 12 hour format, followed by AM/PM. Short for '%I:%i:%S %p'.
%SSeconds with 2 digits.
%sSeconds with 2 digits.
%TTime in 24 hour format. Short for '%H:%i:%S'.
%UWeek number (00-53), when first day of the week is Sunday.
%uWeek number (00-53), when first day of the week is Monday.
%VWeek number (01-53), when first day of the week is Sunday. Used with %X.
%vWeek number (01-53), when first day of the week is Monday. Used with %x.
%WFull weekday name in current locale (Variable lc_time_names).
%wDay of the week. 0 = Sunday, 6 = Saturday.
%XYear with 4 digits when first day of the week is Sunday. Used with %V.
%xYear with 4 digits when first day of the week is Sunday. Used with %v.
%YYear with 4 digits.
%yYear with 2 digits.
%#For str_to_date(), skip all numbers.
%.For str_to_date(), skip all punctation characters.
%@For str_to_date(), skip all alpha characters.
%%A literal % character.

SQL Examples for the FROM_UNIXTIME function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

SELECT from_unixtime(unix_timestamp());
SELECT from_unixtime(unix_timestamp() + 1);
SELECT from_unixtime(unix_timestamp()) + 1;
SELECT from_unixtime(unix_timestamp()) + 0.001;

SELECT from_unixtime(1670799600);
SELECT from_unixtime(1670799600) + 1;
SELECT from_unixtime(1670799600) + 0.001;

SET SESSION time_zone = '+1:00';
SELECT '+1:00' AS time_zone;
SELECT from_unixtime(0);

SET SESSION time_zone = '+0:00';
SELECT '+0:00' AS time_zone;
SELECT from_unixtime(0);

SELECT from_unixtime(unix_timestamp(), '%Y-%m-%d');
SELECT from_unixtime(unix_timestamp(), '%y-%M-%d');
SELECT from_unixtime(unix_timestamp(), '%y-%M-%d %h:%m:%s');
SELECT from_unixtime(unix_timestamp(), 'Date: %Y_%m_%d, Time: %h.%m.%s');

SELECT from_unixtime(111111111111111111111);
SELECT from_unixtime(null);
SELECT from_unixtime(unix_timestamp(), null);

from_unixtime(unix_timestamp())
datetime(19)
2023-03-28 16:03:31
from_unixtime(unix_timestamp() + 1)
datetime(19)
2023-03-28 16:03:32
from_unixtime(unix_timestamp()) + 1
bigint(16)
20230328160332
from_unixtime(unix_timestamp()) + 0.001
decimal(20)
20230328160331.001
from_unixtime(1670799600)
datetime(19)
2022-12-12 00:00:00
from_unixtime(1670799600) + 1
bigint(16)
20221212000001
from_unixtime(1670799600) + 0.001
decimal(20)
20221212000000.001
time_zone
varchar(5) BINARY
+1:00
from_unixtime(0)
datetime(19)
1970-01-01 01:00:00
time_zone
varchar(5) BINARY
+0:00
from_unixtime(0)
datetime(19)
1970-01-01 00:00:00
from_unixtime(unix_timestamp(), '%Y-%m-%d')
varchar(10) BINARY
2023-03-28
from_unixtime(unix_timestamp(), '%y-%M-%d')
varchar(70) BINARY
23-March-28
from_unixtime(unix_timestamp(), '%y-%M-%d %h:%m:%s')
varchar(79) BINARY
23-March-28 02:03:31
from_unixtime(unix_timestamp(), 'Date: %Y_%m_%d, Time: %h.%m.%s')
varchar(32) BINARY
Date: 2023_03_28, Time: 02.03.31
from_unixtime(111111111111111111111)
datetime(19)
NULL
from_unixtime(null)
datetime(19)
NULL
from_unixtime(unix_timestamp(), null)
varchar(0) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the FROM_UNIXTIME() function in MySQL and MariaDB databases

In MySQL and MariaDB the FROM_UNIXTIME() function is used to convert a Unix timestamp represented as Number of seconds since January 1, 1970, to an equivalent date and time. The function returns the date and time in the format "YYYY-MM-DD HH:MM:SS" and can be used to convert a Unix timestamp into a human-readable date and time format, to combine with other date and time functions, and to perform various calculations or manipulations.
FOUND_ROWSFROM_BASE64FROM_DAYSFROM_UNIXTIMEGET_FORMATGREATESTGROUP_CONCAT

Further MySQL und MariaDB SQL Date and Time functions

ADDDATEADDDATE(Date, [INTERVAL] Number [Unit])
More about ADDDATE Function

ADDTIMEADDTIME(Date, Expression)
More about ADDTIME Function

CONVERT_TZCONVERT_TZ(Date, From time zone, To time zone)
More about CONVERT_TZ Function

CURDATECURDATE()
More about CURDATE Function

CURTIMECURTIME([Precision])
More about CURTIME Function

CURRENT_DATECURRENT_DATE(-)
More about CURRENT_DATE Function

CURRENT_TIMECURRENT_TIME([Precision])
More about CURRENT_TIME Function

CURRENT_TIMESTAMPCURRENT_TIMESTAMP([Precision])
More about CURRENT_TIMESTAMP Function

DATEDATE(Date and Time)
More about DATE Function

DATE_ADDDATE_ADD(Date, INTERVAL Number Unit)
More about DATE_ADD Function

DATE_SUBDATE_SUB(Date, INTERVAL Number Unit)
More about DATE_SUB Function

FROM_DAYSFROM_DAYS(Number of days)
More about FROM_DAYS Function

LOCALTIMELOCALTIME([Precision])
More about LOCALTIME Function

LOCALTIMESTAMPLOCALTIMESTAMP([Precision])
More about LOCALTIMESTAMP Function

MAKEDATEMAKEDATE(Year, Day of year)
More about MAKEDATE Function

MAKETIMEMAKETIME(Hours, Minutes, Seconds)
More about MAKETIME Function

NOWNOW([Precision])
More about NOW Function

SEC_TO_TIMESEC_TO_TIME(Seconds)
More about SEC_TO_TIME Function

SLEEPSLEEP(Seconds)
More about SLEEP Function

STR_TO_DATESTR_TO_DATE(String, Format)
More about STR_TO_DATE Function

SUBDATESUBDATE(Date, [INTERVAL] Number [Unit])
More about SUBDATE Function

SUBTIMESUBTIME(Date and Time, Deduction)
More about SUBTIME Function

SYSDATESYSDATE()
More about SYSDATE Function

TIMETIME(Date and Time)
More about TIME Function

TIMEDIFFTIMEDIFF(Date 1, Date 2)
More about TIMEDIFF Function

TIMESTAMPTIMESTAMP(Date [, Addition])
More about TIMESTAMP Function

TIMESTAMPADDTIMESTAMPADD(Unit, Number, Date)
More about TIMESTAMPADD Function

TIMESTAMPDIFFTIMESTAMPDIFF(Unit, Date 1, Date 2)
More about TIMESTAMPDIFF Function

UTC_DATEUTC_DATE()
More about UTC_DATE Function

UTC_TIMEUTC_TIME([Precision])
More about UTC_TIME Function

UTC_TIMESTAMPUTC_TIMESTAMP([Precision])
More about UTC_TIMESTAMP Function

DAYDAY(Date)
More about DAY Function

DAYOFMONTHDAYOFMONTH(Date)
More about DAYOFMONTH Function

DAYOFWEEKDAYOFWEEK(Date)
More about DAYOFWEEK Function

DAYOFYEARDAYOFYEAR(Date)
More about DAYOFYEAR Function

EXTRACTEXTRACT(Unit FROM Date)
More about EXTRACT Function

HOURHOUR(Date and Time)
More about HOUR Function

MICROSECONDMICROSECOND(Date and Time)
More about MICROSECOND Function

MINUTEMINUTE(Date and Time)
More about MINUTE Function

MONTHMONTH(Date)
More about MONTH Function

QUARTERQUARTER(Date)
More about QUARTER Function

SECONDSECOND(Date and Time)
More about SECOND Function

TIME_TO_SECTIME_TO_SEC(Time)
More about TIME_TO_SEC Function

TO_DAYSTO_DAYS(Date)
More about TO_DAYS Function

TO_SECONDSTO_SECONDS(Date and Time)
More about TO_SECONDS Function

UNIX_TIMESTAMPUNIX_TIMESTAMP([Date and Time])
More about UNIX_TIMESTAMP Function

WEEKWEEK(Date [, Mode])
More about WEEK Function

WEEKDAYWEEKDAY(Date)
More about WEEKDAY Function

WEEKOFYEARWEEKOFYEAR(Date)
More about WEEKOFYEAR Function

YEARYEAR(Date)
More about YEAR Function

YEARWEEKYEARWEEK(Date [, Mode])
More about YEARWEEK Function

DAYNAMEDAYNAME(Date)
More about DAYNAME Function

DATE_FORMATDATE_FORMAT(Date and Time, Format)
More about DATE_FORMAT Function

GET_FORMATGET_FORMAT(Type, Format)
More about GET_FORMAT Function

MONTHNAMEMONTHNAME(Date)
More about MONTHNAME Function

TIME_FORMATTIME_FORMAT(Time, Format)
More about TIME_FORMAT Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the FROM_UNIXTIME SQL function: mysql.com and mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer