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

date

Status
Not open for further replies.

mary555

Programmer
Nov 9, 2005
185
CA
i am using asp pages with vbscript and sql server. i need to insert a date into a database. i have a text field on my form called SDate and i need this date value to go into my database with an insert statement....the type of field it is in the database is date/time. i've tried so many variations of code that i thought would work but nothing has worked so far! please help
 
If you have a Date/Time col. in a DB, try to insert NOW()

If you have a Date/Time of other format than "NOW()", then try CDate(SDate)

Regards
 
if i'm not mistaken, you have to wrap # signs around a text item to go into a date field. like this:
"#" & the_date & "#" to the sql, the date would look like this:
#05/23/2006#
this piece of code seems to work:
INSERT INTO Table1(last_na, ranking, the_date)
values("john", 12, #05/23/2006#):
 
when i put that code how you have it, i get the error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The name '#05' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

when i put it like this:
SQLStmt.CommandText = "Insert into table (P, R, Pl,G,L,R,D,T,StartDate) values ('"&ValCombo1&"','"&ValCombo2&"','"&ValCombo3&"','"&ValCombo4&"', '"&ValCombo5&"', '"&ValComboCause&"', '"&ValComboAmp&"', '"&ValComboType&"',"&#05/23/2006#&")"

then it doesn't give an error but it still puts 01/01/1900 in the database
 
You may try to replace this:
[tt]&"',"&#05/23/2006#&")"[/tt]
with this:
[tt]&"','2006-05-23')"[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top