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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dateadd using value from a form field

Status
Not open for further replies.

NickyJay

Programmer
Sep 1, 2003
217
GB
Hi,

can anyone give me some pointers??

I have a form to input purchase order details and need to work out the intended delivery date based on the date the purchase order was created (NOW() function used) and the number of days selected from an option list on the form.

The date needs to be worked out and automatically pasted into the appropriate database field in a mysql database.

So far ive looked at the DATEADD fuction but this seems to want a number aas the second parameter rather than me being able to identify the from field.

Help!!
 
You can substitute the form field value (it is a number, isn't it?):

<cfset promise_date = dateadd("d",form.numberofdays,form.createdate)>

HTH,

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
Hi,

thanks for replying :)
Yes the value is a number, i have tried this and i get "Parameter validation error for function DATEFORMAT." doesn't seem to like anything other than a number!

Thanks
Nicola
 
DATEFORMAT? I thought we were discussing DATEADD. My apologies for the misleading advice

That said, the DATEADD function is not supported in ColdFusion. Do the math in a query, using the DATEADD function.

UPDATE Mytable SET mydate = dateadd(d,#form.numberofdays#,#form.createdate#)

I'm not familiar with MySQL, so check the correct syntax of the function, especially the datepart attribute.

HTH,

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
dateAdd() is exactly what you would use...

#dateAdd("d",form.days,)#

Code:
<cfoutput>

<cfparam name="form.days" default="0">

<form action="" method="post">
	<select name="days">
		<option value="1">1<option>
		<option value="2">2<option>
		<option value="3">3<option>
		<option value="4">4<option>
		<option value="5">5<option>
	</select>
	<br/>
	<input type="submit" name="go" />
</form>



#dateAdd("d",form.days,now())#

</cfoutput>

 
Thanks for that guys, managed to get it to work :)
Merry christmas to you both ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top