VBScript DateSerial Function

Definition and Usage

The DateSerial function can return a Variant of the Date type for the specified year, month, and day.

That is to say,The DateSerial function can combine year, month, and day into a date..

Syntax

DateSerial(year,month,day)
Parameter Description
year Mandatory. A number between 100 and 9999, or a numeric expression. Values between 0 and 99 are considered to be from 1900 to 1999. For all other year parameters, please use the full 4-digit year.
month Mandatory. Any numeric expression. If greater than 12, the date is calculated from the 12th month of the year, adding month minus 12 months; if less than 1, the date is calculated from the 1st month of the year, subtracting 1-month months.
day Mandatory. Any numeric expression. If greater than the number of days in the current month, the date is calculated from the number of days in the current month, adding day minus the number of days in the current month; if less than 1, the date is calculated from the 1st day of the month, subtracting 1-day days.

Instance

Example 1

document.write(DateSerial(1996,2,3)) 'Normal calling method'

Output:

1996/2/3

Example 2

document.write(DateSerial(95,13,10)) '13 months=1 year+1 month'

Output:

1996/01/10

Example 3

document.write(DateSerial(96,-1,10)) '-1 month needs to be calculated from 1st month, 1-(-1)=2 months'

Output:

1995/11/10

Example 4

document.write(DateSerial(95,2,30)) '95 year February has 28 days, so 30th=January+2 days'

Output:

1995/03/02

Example 5

document.write(DateSerial(95,2,-2)) '-2 days need to be calculated from 1st day, 1-(-2)=3 days'

Output:

1995/01/29

Example


'1990-20=1970, 9-2=7, 1-1=0, 0 days need to be calculated from 1st day, 1-0=1 day.',

Output:

1970/6/30