MySQL NOW() Function

The NOW() function in MySQL retrieves the current date and time from the database server. This is incredibly useful for various database operations involving timestamps.



NOW(): Definition and Usage

NOW() is frequently used for logging events, tracking data modifications, or generating time-based reports. The output format can be a string (YYYY-MM-DD HH:MM:SS) or a numeric representation (YYYYMMDDHHMMSS.uuuuuu), depending on the context of your query. The exact time returned reflects the server's system clock.

Syntax

Syntax

NOW()
      

Examples

Getting the Current Timestamp

This query returns the current date and time.

Syntax

SELECT NOW();
      
Output

2024-11-08 11:35:12 (Example; the actual time will vary based on when you run the query)
      

Adding to the Current Timestamp

Adding 1 to the timestamp adds one day. The result's format might vary slightly based on your MySQL server's settings.

Syntax

SELECT NOW() + 1;
      
Output

2024-11-09 11:35:12 (Example; one day added to the current timestamp)