Date/Time Functions – YEAR()

I am going to hang on with writing my series of short articles or tidbits on Transaction SQL date/time functions.

Most, if not all, modern day computer systems collect data which contains dates and times.

Not only is it important to know when a sales order came in, but we should fulfill the request using some type of queue (LIFO). If if was a stack (FIFO) implementation, the first person may never get his order!

Today, I will be exploring functions that take a datetime variable as input and return an integer as output.

The YEAR() function returns an integer for a given datetime variable. Depending upon precision, the minimum return value could be 0001, 1753, or 1900 and the maximum value
can be 2079 or 9999.

The examples below are sample calls to the function. The inputs puts are valid date, null value and a empty string.

The output from the test is listed below. It is surprising that an empty string returns a value of 1900.

To rehash the article, this function returns the year from a datetime variable in integer format.

Related posts

Leave a Comment