Purpose
Returns the year component of a date value. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
Year( date_expr )
date_expr is a date expression.
Return Value
SmallInt
Description
If the Set Date Window() statement is off, then the year also depends on your system clock.
Examples
The following example shows how you can use the Year() function to extract only the year component of a particular date value.
Dim sampleDate as Date
Set Date Window Off
sampleDate=StringToDate("10/1/98")
Print Year(sampleDate)
' 2098 (or 1998 if the computer's system date is set in the 1900's)
' because with date windowing off MapInfo uses the current century
Set Date Window 50
' now assume that two-digit dates fall in the period 1950-2049
print Year(sampleDate)
' still 2098, because date variable has already been assigned!
sampleDate=StringToDate("10/1/98")
' re-assign variable now that the date window has changed
print Year(sampleDate) ' 1998
Undim sampleDate
The Year() function can also take a string, rather than a Date variable. In that case, implicit conversion to date format occurs. The following example illustrates this:
Set Date Window Off
Print Year("10/1/99") ' prints 2099
Set Date Window 50
Print Year("10/1/99") ' prints 1999
You can also use the Year() function within the SQL Select statement. The following Select statement selects only particular rows from the Orders table. This example assumes that the Orders table has a Date column, called OrderDate. The Select statement's Where clause tells MapInfo Pro to only select the orders from December of 2013.
Open Table "orders"
Select * From orders
Where Month(orderdate) = 12 And Year(orderdate) = 2013
See Also:
CurDate() function, Day() function, DateWindow() function, Minute() function, Month() function, Second() function, Weekday() function