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

help inserting current date into db

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
I'm trying to insert the current date into the db with the following code, but it's showing up as 1/1/1900 in the db.

I know I can just set the default value in the db to today's date, but I need to do this with CF.

Anyone see what I'm doing wrong?

<cfset today = DateFormat(Now(),&quot;mm/dd/yy&quot;)>

<cfquery name=&quot;insert&quot; datasource=&quot;#ds#&quot;>
INSERT INTO sri_contact(blah1, blah2, date_sent)
VALUES(#blah1#, #blah2#, #today#)
</cfquery>
 
We need to know what database you're using in order to reply appropriately...
 
Since you said that it's showing up as &quot;1/1/1900&quot;, I assume that you're using SQL Server. That's what it defaults to for dates if one is not supplied.

If you are using SQL Server, try using <cfqueryparam> when you pass the date:
Code:
<cfquery name=&quot;insert&quot; datasource=&quot;#ds#&quot;>
  INSERT INTO sri_contact(blah1, blah2, date_sent)
  VALUES(#blah1#, #blah2#, <cfqueryparam value=&quot;#today#&quot; cfsqltype=&quot;CF_SQL_DATE>
</cfquery>



Hope This Helps!

Ecobb

&quot;My work is a game, a very serious game.&quot; - M.C. Escher
 
It is SQL SERVER 2000

Turns out, surrounding the #today# variable in single quotes solves the problem.

Insert...
Values(..., '#today#')

Thanks for the help anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top