Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AddDate function in VbScript

Status
Not open for further replies.

kazai

Programmer
Oct 19, 2001
24
US
The scenario is:
Dim Borrow_date
Borrow_date = Request.Form("txt_BorrowDate")
// Borrow_date actually contains a date(in string form, though i have declared it as dim only)
// I now need to add 15 days to this, using the DateAdd function in VBSript.
I say, DateAdd("dd",15,Borrow_date)
It gives me an error saying expected string.
Is there a way I can accomplish this, or can I use Request.Form("txt_BorrowDate") directly inplace of Borrow_date in the DateAdd function?

Thanks,
Radhika.
 
The code below worked great in my test environment.

Code:
dim Borrow_date
Borrow_date = CDate(Request.Form("txt_BorrowDate"))

Response.Write DateAdd("d",15,Borrow_date)

Notes:

#1: Only a single d in the DateAdd function to specify days.

#2: It's always good practice to convert strings into dates using CDate("somedatestring") before performing and methods that are looking for dates. In this case, both the date type and the string type worked on the DateAdd function. I just like to keep it good practice anyways. Besides, it's much easier to troubleshoot if you get errors.

Hope this helps.. :)

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top