SQL: Insert current time or timestamp

This entry is part 11 of 20 in the series SQL Tutorial

It is common for developer to insert a timestamp into each record marking the time a record is created.

With timestamp, we could for example, know when a purchase of an item is made.

In the example below, we make a slight modification to the example sql fiddle and add a time that a record is created.

CREATE TABLE supportContacts 
 id int auto_increment primary key, 
 type varchar(20), 
 details varchar(30), 
 current datetime

INSERT INTO supportContacts
(type, details, current)
('Email', 'admin@sqlfiddle.com', now()),
('Twitter', '@sqlfiddle',now());

Notice that we use a variable current with a datetime datatype.  The timestamp is inserted by now().

Sometimes, we use select now() to check the current time of the server system.

Series Navigation<< SQL: Insert Into
SQL: Data Types >>

Leave a comment

Leave a Reply