SQL DATE

There are different formats for dates and times stored in different database systems.

The types of data in each column are defined when creating the table.

Data types for dates and times in MySQL database

TypeFormatExample
DATEYYYY-MM-DD2008-11-11
DATETIMEYYYY-MM-DD HH:MM:SS2008-11-11 13:23:44
TIMESTAMPYYYY-MM-DD HH:MM:SS
YEARYYYY o YY

Functions for MySQL on these data types earlier date

NOWIt displays the date and time. For example: 2008-11-11 12:45:34
CURDATEIt displays the current date. For example: 2008-11-11
CURTIMEIt displays the current time. For example: 12:45:34
DATEIt displays the date of an expression date / time
EXTRACTIt shows a part of an expression date / time
DATE_ADDIt shows a date as a sum of a time interval to a date
DATE_SUBIt is used to subtract a date as a time interval to a date
DATEDIFFIt displays the number of days between 2 dates
DATE_FORMATIt displays a date and time in different formats

Data types for dates and times in SQL Server database

DATEFormat YYYY-MM-DD
DATETIMEFormat YYYY-MM-DD HH:MM:SS
SMALLDATETIMEFormat YYYY-MM-DD HH:MM:SS
TIMESTAMPThis value is generated based on system time. It is updated automatically.

Functions for SQL Server on the data types above date and time

GETDATEIt displays the date and time
DATEPARTIt shows part of a date and time
DATEADDIt displays a date DATEADD as addition or subtraction of a time interval on a date
DATEDIFFIt shows the time between 2 dates
CONVERTIt displays the date and time in different formats

Examples of using date and time

CREATE TABLE orders ( orderid int NOT NULL, productName varchar (50) NOT NULL, orderDate datetime NOT NULL PRIMARY KEY (orderid) )
orderidproductNameorderdate
1office paper 2012-02-23 14:05:00

If you want to store only the date (and time) will use the data type 'date' instead of 'datetime'.