The Excel YEAR Function
Basic DescriptionThe Excel YEAR function, when supplied with a date, returns an integer representing the year. The format of the function is : YEAR( Date )
where the Date argument can be supplied to the function as either :
Warning: If you attempt to input the Date argument as text, there is a chance that Excel may misinterpret this due to different date systems, or date interpretation settings. Also, although you can input the Date as a serial number, this is not recommended as the serial numbers may vary across different computer systems. ExampleThe following example shows the function used to extract the year from 3 different dates. The spreadsheet on the left shows the format of the function and the spreadsheet on the right shows the results for the 3 dates.
Note that, in the above examples, as recommended by Microsoft, the date value is always supplied as either a reference to a cell containing a date, or as a value returned from another function. Further examples of the Excel Year function can be found on the Microsoft Office website. Common Error With the Excel Year FunctionProblem:
The result of your Year function looks like a date (eg. "01/01/1900"), instead of returning an integer. Solution:
This problem arises because the new cell or column is formatted as a 'date'. In this case, it is only the formatting of the cell that is wrong, NOT the value returned by the function. To correct this,
- See the Excel Formatting page for more details on formatting in Excel. The Year Function In VBAThe Year function is also a built-in function in VBA (used for writing Excel Macros). Within VBA, the function takes exactly the same format as when used in an Excel spreadsheet: YEAR( Date )
For example:
After running the above snippet of VBA code, the variable 'YearNum' holds the value '2009'. |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Copyright © 2008-2010 ExcelFunctions.net |