ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 3rd, 2003, 10:38 AM
davidagnew davidagnew is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 7 davidagnew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old September 3rd, 2003, 10:49 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > AddDate Function using a variable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT