Collections:
NOW() - Start Time of Execution
How to obtain the start time of an execution unit using the NOW() function?
✍: FYIcenter.com
NOW(prec) is a MySQL built-in function that
returns the start time of an execution unit
with a given precision of fractional seconds.
For example:
SELECT NOW(), SLEEP(2), NOW(); -- +---------------------+----------+---------------------+ -- | NOW() | SLEEP(2) | NOW() | -- +---------------------+----------+---------------------+ -- | 2023-11-22 11:43:07 | 0 | 2023-11-22 11:43:07 | -- +---------------------+----------+---------------------+ SELECT NOW(), NOW()+1; -- +---------------------+----------------+ -- | NOW() | NOW()+1 | -- +---------------------+----------------+ -- | 2023-11-22 12:02:40 | 20231122120241 | -- +---------------------+----------------+ SELECT NOW(6), NOW(6)+1; -- +----------------------------+-----------------------+ -- | NOW(6) | NOW(6)+1 | -- +----------------------------+-----------------------+ -- | 2023-11-22 12:03:08.505415 | 20231122120309.505415 | -- +----------------------------+-----------------------+
Note that NOW() returns the start time of an execution unit like a statement, a stored function or a trigger. Calling NOW() multiple times will give you the same timestamp.
SELECT NOW(), SLEEP(2), NOW(); -- +---------------------+----------+---------------------+ -- | NOW() | SLEEP(2) | NOW() | -- +---------------------+----------+---------------------+ -- | 2023-11-22 12:05:07 | 0 | 2023-11-22 12:05:07 | -- +---------------------+----------+---------------------+
Reference information of the NOW() function:
NOW(prec): tm Returns a constant time that indicates the time at which the statement, a stored function or a trigger, began to execute. Returns the current timestamp as a value in 'YYYY-MM-DD hh:mm:ss.SSSSSS' or YYYYMMDDhhmmss.SSSSSS format, depending on whether the function is used in string or numeric context. Arguments, return value and availability: prec: Optional. Default is 0. The precision of fractional seconds. tm: Return value. The start time of the execution unit. Available since MySQL 4.
Related MySQL functions:
⇒ PERIOD_ADD() - Adding Months to Period
2023-11-17, 1112🔥, 0💬
Popular Posts:
Where to find Oracle database server tutorials? Here is a collection of tutorials, tips and FAQs for...
Where to find answers to frequently asked questions on CREATE, ALTER and DROP Statements in MySQL? H...
How To View Data Files in the Current Database in Oracle? If you want to get a list of all tablespac...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
What Happens If the UPDATE Subquery Returns Multiple Rows in SQL Server? If a subquery is used in a ...