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

The SYSDATE SQL Function in MySQL and MariaDB - System date and time

SYSDATESyntax:SYSDATE()
Return value:DATETIME
Function type:Date and Time function
Function Description

The SYSDATE() function returns the current date and time as a string YYYY-MM-DD hh:mm:ss or numerically as BIGINT YYYYMMDDhhmmss or as DECIMAL YYYYMMDDhhmmss.microseconds, depending on whether the function is used in string or numeric context.

The value is expressed in the format of the current session time zone.


The SYSDATE() function returns the exact time the function is executed.

In contrast, the NOW() function returns the time when execution of the statement started.

Inside routines and triggers, NOW() returns the time the routine started executing.


The "Precision" argument can be specified to indicate a sub-second precision from 0 to 6 digits.

The specification of "Precision" must be a written number from 0-6. Expressions or variables produce a syntax error, larger values ​​produce a precision error.

Setting the system variable timestamp does not affect the SYSDATE() function.

SQL Examples for the SYSDATE function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12

SELECT sysdate(), sysdate() + 1, sysdate() + 0.001;
SELECT sysdate(6), sysdate(6) + 1, sysdate(6) + 0.001;

select now(), sleep(2), now(0);
select sysdate(), sleep(2), sysdate(0);

SELECT sysdate(7);
SELECT sysdate(3 + 2);
SET @a=3;
SELECT sysdate(@a);

sysdate()
sysdate() + 1
sysdate() + 0.001
datetime(19)bigint(16)decimal(20)
2023-03-27 14:36:442023032714364520230327143644.001
sysdate(6)
sysdate(6) + 1
sysdate(6) + 0.001
datetime(26)decimal(23)decimal(23)
2023-03-27 14:36:44.00839320230327143645.00839420230327143644.009395
now()
sleep(2)
now(0)
datetime(19)int(1)datetime(19)
2023-03-27 14:36:4402023-03-27 14:36:44
sysdate()
sleep(2)
sysdate(0)
datetime(19)int(1)datetime(19)
2023-03-27 14:36:4602023-03-27 14:36:48
  select sysdate(7) 
errno: 1426  sqlstate: 42000  error: Too big precision 7 specified for 'sysdate'. Maximum is 6  
  select sysdate(3 + 2) 
errno: 1064  sqlstate: 42000  error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '+ 2)' at line 1  
  select sysdate(@a) 
errno: 1064  sqlstate: 42000  error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@a)' at line 1  

Examples of how setting the system variable timestamp affects

 1
 2
 3
 4
 5

select now(), SYSDATE();
set session timestamp = UNIX_TIMESTAMP()+1000;
select now(), current_timestamp(), localtime(), sysdate();

now()
SYSDATE()
datetime(19)datetime(19)
2023-03-27 14:11:192023-03-27 14:11:19
now()
current_timestamp()
localtime()
sysdate()
datetime(19)datetime(19)datetime(19)datetime(19)
2023-03-27 14:27:592023-03-27 14:27:592023-03-27 14:27:592023-03-27 14:11:19
The examples were created with the MyWAY SQL manager: Download

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

The SYSDATE() function in MySQL and MariaDB returns the current system date and time in the format "YYYY-MM-DD HH:MM:SS" from the database server. The function is executed at query execution time, not at the beginning of the transaction. If there are multiple statements in a transaction using the SYSDATE() statement, each call may produce different results depending on the time it takes to execute the statements. SYSDATE() returns the date and time based on the database server's system clock.
SUBTIMESUMSYS_GUIDSYSDATESYSTEM_USERTANTIME

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

FROM_UNIXTIMEFROM_UNIXTIME(Unix timestamp [, Format])
More about FROM_UNIXTIME 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

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 SYSDATE SQL function: mysql.com and mariadb.com and w3schools.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer