In computer programming, a data type tells the compiler how the programmer is intended to use data in a program. The basic data types are integers, boolean, floating points, and characters.
This temporal data type in YYYY-MM-DD HH:MM:SS
. Moreover, the timestamp datatype has a length of 19 characters.
Note: When you insert a timestamp value into a table, the SQL server converts it to the
format instead of the respective time zone. UTC Coordinated Universal Time
CREATE TABLE Table_Name (variable_name TIMESTAMP);
In this code snippet, we are heading to create a random table, which will contain an attribute of TIMESTAMP
type. Furthermore, we will insert some random values to try out.
-- created a clock table with one attributeCREATE TABLE clock (record TIMESTAMP);-- set current session to '+00:00' UTCSET time_zone='+00:00';-- Insert values into clock table YYYY-MM-DD HH:MM:SSINSERT INTO clock VALUES('2022-06-07 08:43:59');INSERT INTO clock VALUES('2022-06-07');-- fetch all timestamp records from tableSELECT record FROM clock;
(record)
of TIMESTAMP
type.SET time_zone=’+00:00’;
timestamp sets the current SQL server environment instance time zone to '00:00'
UTC. It will intact the data integrity that is going to be inserted.Note: The format for the timestamp data type:
YYYY-MM-DD HH:MM:SS
. It consists of two parts, one is the date and the other is time. Where the date is required, while time is optional.
clock
table.