Generating Date variables by using DateSerial function in ASPBy dateserial function in VBScript used in ASP we can generate date variable by using different variables for day, month and year. This is a quite useful as we can take different user input and create a date variable out of it. We can't create a date variable by placing the variables within two # marks. Like this
The above code will give error message. Let us start with the syntax of dateserial function.
The above function takes three inputs month, date and year and generates a date variable. The date variable then can be used for normal operations. Here is an example of generating date variable.
The above code will return 2/28/2007.
DateSerial can be used to generate different dates before or after the day entered. Here is an example to get next day of the given date.
Same way we can get the date variable for one month before the dates like this
For five years advance date, here it is
DateSerial function takes care of leap years also. Check this code again
We will get 3/1/2007 as output but if we change the value of year to 2008 ( d1="2008") then the out put will change to 2/29/2008
DateSerial function is mostly used to collect user enter data and generating a date variable out of it.
This article is written by plus2net.com team.
Be the first to post comment on this article : |