How to get current date & time in MySQL?

Samuel Nicholson picture Samuel Nicholson · Oct 8, 2013 · Viewed 527.5k times · Source

Is there a value or command like DATETIME that I can use in a manual query to insert the current date and time?

INSERT INTO servers (
  server_name, online_status, exchange, disk_space, network_shares
) VALUES(
  'm1', 'ONLINE', 'ONLINE', '100GB', 'ONLINE' 'DATETIME' 
)

The quoted DATETIME value at the end is where I want to add the current date and time.

Answer

francisco.preller picture francisco.preller · Oct 8, 2013

You can use NOW():

INSERT INTO servers (server_name, online_status, exchange, disk_space, network_shares, c_time)
VALUES('m1', 'ONLINE', 'exchange', 'disk_space', 'network_shares', NOW())