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_
Even though there are many accepted answers, I think this way is also possible:
Create your 'servers' table as following :
CREATE TABLE `servers`
(
id int(11) NOT NULL PRIMARY KEY auto_increment,
server_name varchar(45) NOT NULL,
online_status varchar(45) NOT NULL,
_exchange varchar(45) NOT NULL,
disk_space varchar(45) NOT NULL,
network_shares varchar(45) NOT NULL,
date_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
);
And your INSERT statement should be :
INSERT INTO servers (server_name, online_status, _exchange, disk_space, network_shares)
VALUES('m1', 'ONLINE', 'ONLINE', '100GB', 'ONLINE');
My Environment:
Core i3 Windows Laptop with 4GB RAM, and I did the above example on MySQL Workbench 6.2 (Version 6.2.5.0 Build 397 64 Bits)
Yes, you can use the CURRENT_TIMESTAMP()
command.
See here: Date and Time Functions
In database design, iIhighly recommend using Unixtime for consistency and indexing / search / comparison performance.
UNIX_TIMESTAMP()
One can always convert to human readable formats afterwards, internationalizing as is individually most convenient.
FROM_ UNIXTIME (unix_timestamp, [format ])
İf you make change default value to CURRENT_TIMESTAMP
it is more effiency,
ALTER TABLE servers MODIFY COLUMN network_shares datetime NOT NULL DEFAULT CURRENT_TIMESTAMP;