Developer Documentation Library > Scripting > UNICOM Intelligence Function Library > Date and time functions > DatePart
 
DatePart
Returns a specified part of a given date.
Syntax
DatePart(Val, Interval)
Parameters
Val
Type: Date
The date of which you want to return a part.
Interval
Type: Text
Defines the part of the date that is to be returned. See Value of Interval.
(return)
Type: Long
The specified part of the date.
Remarks
If you use the function in an SQL query, use single quotation marks (' ') instead of double quotation marks (" ") when specifying the Interval parameter.
Val is interpreted according to the input locale.
In some locales, when you use the "ww" option to return the week of the year, the week number for the first days of January might be returned as 53 and for the last days of December it might be returned as 1. For example, if the locale defines the first day of the week as Monday and the first week of the year as the first full week, the week number is returned as 53 for the first few days in a year in which the first Monday falls on January 7.
Example
In this example the DatePart function is used to return the year from the current system date (which is in turn returned by the Now function). For example, on 31 January 2002, this example would return 2002.
DatePart(Now(), "yyyy")
For an example of using DatePart in combination with the WeekdayName function to return the name of the day on which an interview was completed, see WeekdayName
See also
DateAdd
Date and time functions