SQL DATE data type functions
The DATE data type typically takes 4 bytes of storage in a database and can hold date values with a range of 1000-01-01 to 9999-12-31. The TIMESTAMP
data type is similar to the DATE data type, but it also includes information about the time to a precision of one second. The format used to store timestamp values is typically YYYY-MM-DD HH:MM:SS.
There are several date functions provided by the SQL engine to manipulate the date and time information stored in date or DateTime
columns. Let’s look at each of them in detail.
Figure 4.1 – DateTime functions
EXTRACT
The SQL EXTRACT
function is used to extract a part of a date or a timestamp value. The function takes two arguments: the first is the part of the date or timestamp that you want to extract (such as the year, month, or day), and the second is the date or timestamp value that you want to extract from. The syntax for the EXTRACT function is as follows: