|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
AddDate Function using a variable
Hello,
I need to use the AddDate Function but include a variable to using a variable. so instead of .... DateAdd("d", 7, Now()) Instead of the "7" - I would like to use a variable - taking the value from a text box i.e. <% Dim variable variable = request ("textbox_value") Response.Write DateAdd("d", " & variable & ", Now()) %> I cant seem to get this to work. has anyone got any ideas?? Thanks |
|
#2
|
|||
|
|||
|
When you use the Request() it *always* returns a STRING
Now looking at the documentation of the DateAdd() function it reads: ------------------------------------------------------------------- DateAdd(interval, number, date) ------------------------------------------------------------------- Notice the second parameter, in bold, it says: number so its expecting a number NOT a STRING Now, you'll need to CONVERT/CAST that STRING into a number so: <% Dim lngNumber lngNumber = Trim(Request("textbox_value")) 'Notice that I've prefixed the variable *lngNumber* with lng 'but it is *still* a string since I'm using the Request() 'Now, let's make sure the user did enter a value inside the <textbox> of yours... If lngNumber = "" then Response.Write "You must enter data in textbox" Response.End Else 'Let's make sure the data entered is a numeric value because 'we need a number remember!!! If NOT IsNumeric(lngNumber) Then Response.Write "you must provide a numeric value!" Response.End End If End If 'Now if the code reaches this then we are ok! 'But we *still* need to convert/cast that variable into a number! 'So: Response.Write DateAdd("d", Clng(lngNumber), Now()) %> 'NOTE: You could also look into using CInt() instead of CLng() Hope this helps! Sincerely Vlince |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > AddDate Function using a variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|