Caché Basic Reference
DateSerial

 Server:docs2 Instance:LATEST User:UnknownUser

 [ Home ]  >  [ Caché Development References ]  >  [ Caché Basic Reference ]  >  [ Caché Basic Functions ]  >  [ DateSerial ] Go to: Description Examples Notes See Also Search:

Returns the date for a specified year, month, and day.
Synopsis
`DateSerial(year,month,day)`
Arguments
 year A four-digit integer between 1841 and 9999, inclusive, a two-digit integer, or a numeric expression that evaluates to an integer within these ranges. month A positive or negative integer or a numeric expression that evaluates to an integer. A month value of 0 or the empty string ("") is interpreted as the last month of the previous year. A negative month value backs up the specified number of months from the last month of the previous year. Thus -1 is the 11th month of the previous year. day A positive or negative integer or a numeric expression that evaluates to an integer. A day value of 0 or the empty string ("") is interpreted as the last day of the previous month. A negative day value backs up the specified number of days from the last day of the previous month. Thus, a day value of -1 is interpreted as the day before the last day of the previous month.
Description
DateSerial takes the input arguments and generates a valid date in the format:
`mm/dd/yyyy`
The range of numbers for each DateSerial argument can be an exact date value or a relative date value. A relative date value is an integer value outside the accepted range for the unit; that is, 1–31 for days and 1–12 for months. In this case, DateSerial uses these numbers to calculate a valid date. Any numeric expression can be used to represent some number of days, months, or years before or after a certain date.
Year values between 0 and 99, inclusive, are interpreted as the years 1900–1999. The empty string ("") is interpreted as the year 1900. For all other year arguments, use a complete four-digit year (for example, 2005). The earliest allowed year value is 1841.
Examples
The following example uses numeric expressions instead of absolute date numbers. Here the DateSerial function returns a date that is the day before the first day (1 – 1) of two months before August (8 – 2) of 10 years before 1990 (1990 – 10); in other words, May 31, 1980.
```Dim MyDate1, MyDate2
MyDate1 = DateSerial(1970, 1, 1)
MyDate2 = DateSerial(1990 - 10, 8 - 2, 1 - 1)
Println MyDate1  ' Returns 01/01/1970 (January 1, 1970)
Println MyDate2  ' Returns 05/31/1980```

The following example uses month values of 0, the empty string (""), and negative numbers:
```Println DateSerial(2009,"",3)  ' Returns 12/03/2008
Println DateSerial(2009,0,3)   ' Returns 12/03/2008
Println DateSerial(2009,-1,3)  ' Returns 11/03/2008
Println DateSerial(2009,-2,3)  ' Returns 10/03/2008```

The following example uses day value that is not valid for the specified month. DateSerial is aware of leap year values and adjusts the month accordingly:
`Println DateSerial(2009,2,29)  ' Returns 03/01/2008`

The following example uses day and month values that are larger than the number of days in the specified month and monthsd in a year. DateSerial adjusts the day, month, and year accordingly:
`Println DateSerial(2009,13,40)  ' Returns 02/09/2010`

Notes
When any argument exceeds the accepted range for that argument, it increments to the next larger unit as appropriate. For example, if you specify 35 days, it is evaluated as one month and some number of days, depending on where in the year it is applied. However, if any single argument is outside the range -32,768 to 32,767, or if the date specified by the three arguments, either directly or by expression, falls outside the acceptable range of dates (12/31/1840 through 12/31/9999), an error occurs.