Great! Now, let's see how we can manipulate date and time data. SQL Server provides functions that allow us to extract parts of dates and/or times. The simplest of them are:
YEAR()—extracts the year from a string or a field and returns it as an integer; if the year value is zero or if there is only time data in that field, the function returns the base year, which is 1900.
YEAR(), except it returns the number of the month as an integer. If the month value is zero or the field contains only time data, the function returns the base month (1). Note: January is denoted by a 1, February by 2, and so on.
YEAR(), but returns the day as an integer. If the day value is zero or contains only time data, the function returns the base day (1). Note:
DAY() returns the day of the month (i.e., 1 for the first of the month).
Here's how these functions work:
YEAR(Date) AS Year,
MONTH(Date) AS Month,
DAY(Date) AS Day
This query extracts the day, month, and year of flights using the data in the