DateSerial Function

   
DateSerial Function

Class

Microsoft.VisualBasic.DateAndTime

Syntax

 DateSerial(   year   ,   month   ,   day   ) 
year (required; Integer)

Number between 100 and 9999, inclusive, or a numeric expression

month (required; Integer)

Any numeric expression to express the month between 1 and 12

day (required; Integer)

Any numeric expression to express the day between 1 and 31

Return Value

A Date representing the date specified by the arguments

Description

Returns a Date whose value is specified by the three date components (year, month, and day).

For the function to succeed, all three components must be present, and all must be numeric values. The value returned by the function takes the short date format defined by the Regional Settings applet in the Control Panel of the client machine.

Rules at a Glance

  • If the value of a particular element exceeds its normal limits, DateSerial adjusts the date accordingly . For example, if you tried DateSerial(96,2,31) February 31, 1996 DateSerial returns March 2, 1996.

  • You can specify expressions or formulas that evaluate to individual date components as parameters to DateSerial . For example, DateSerial(98,10+9,23) returns 23 March 1999. This makes it easier to use DateSerial to form dates whose individual elements are unknown at design time or that are created on the fly as a result of user input.

Example

 Dim iYear As Integer = 1987 Dim iMonth As Integer = 3 + 11 Dim iday As Integer = 16 MsgBox(DateSerial(iYear, iMonth, iday)) 

Programming Tips and Gotchas

  • If any of the parameters exceed the range of the Integer data type (-32,768 to 32,767), an error (runtime error 6, "Overflow") is generated.

  • DateSerial handles two-digit years in the same way as other Visual Basic date functions. A year argument between 0 and 29 is taken to be in the 21st century (2000 to 2029); year arguments between 30 and 99 are taken to be in the 20th century (1930 to 1999). Of course, the safest way to specify a year is to use the full four digits.

See Also

DatePart Function, DateString Property, DateValue Function

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net