Sunday, December 22, 2024

MySQL LOCALTIMESTAMP() Function

 The LOCALTIMESTAMP() function in MySQL returns the current date and time in the session time zone, which typically corresponds to the time zone set for the MySQL server or the session. The result is returned in the YYYY-MM-DD HH:MM:SS format.

Syntax:

LOCALTIMESTAMP()

Example:

SELECT LOCALTIMESTAMP();

This will return the current date and time in the session time zone, like:

2024-12-23 14:30:45

Notes:

  • LOCALTIMESTAMP() is equivalent to CURRENT_TIMESTAMP() and NOW(), both of which return the current date and time.
  • If you want to use a specific time zone, you can modify the session time zone using the SET time_zone command.

For example:

SET time_zone = '+00:00';  -- Set UTC time zone
SELECT LOCALTIMESTAMP();

This would return the current local timestamp adjusted to UTC time.

Let me know if you'd like more details!

No comments:

Post a Comment