SQL PHP HTML ASP JavaScript articles and free scripts to download
ASP > Date Today

Generating Date variables by using DateSerial function in ASP

By 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

My_date=#my_month, my_day,1985#

The above code will give error message. Let us start with the syntax of dateserial function.

DateSerial(yyyy, dd, mm)

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.

Dim d1, d2, d3
Response.Write DateSerial(d1,d2,d3)

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.

Response.Write DateSerial(d1,d2,d3+1)

Same way we can get the date variable for one month before the dates like this

Response.Write DateSerial(d1,d2-1,d3)

For five years advance date, here it is

Response.Write DateSerial(d1+5,d2,d3)

DateSerial function takes care of leap years also. Check this code again

Dim d1, d2, d3
Response.Write DateSerial(d1,d2,d3+1)

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.

Be the first to post comment on this article :


Post Comment This is for short comments only. Use the forum for more discussions.
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer