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

DateTime field 2

Status
Not open for further replies.

DaveCrate

Technical User
Jan 12, 2004
41
US
When fields from a asp form are inserted into a table, can the date and time of that insert be inserted as a field with it.

example: table
field name: ProductName, Produced, DateProduced, DateEntered
row: Part1 1000 01/06/2005 01/07/2005 09:42 AM
 
It depends on how you do the INSERT. You should be able to add the SQL Server function GETDATE().

INSERT INTO mytable
VALUES ('Part1', 1000, '01/06/2005', GETDATE())

-SQLBill
 
The column name is DateEntered. My fault
Should the last value be where GetDate()goes.

I looked at your code and mine really needs to be cleaned up.

mine:

strSQL = ""
strSQL = strSQL & "INSERT INTO Bliss1TPM "
strSQL = strSQL & "(Produced, Rejected, RunTime, DownTime, Shift, ProducedDate, Line, EnteredDate) " & vbCrLf
strSQL = strSQL & "VALUES ("
strSQL = strSQL & "'" & intProduced & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & intRejected & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & intRunTime & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & intDownTime & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strShift & "'"
strSQL = strSQL & ", "
strSQL = strSQL & DATE_DELIMITER & datDateTimeField & DATE_DELIMITER
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strLine & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & GetDate() & "'"
strSQL = strSQL & ");"


Thanks for replies!
Suggestions?
Dave
 
You are on the right track...did u get any errors with the above code...

-L
 
GETDATE() shud work without any problems...

try this..
Code:
strSQL = "INSERT INTO Bliss1TPM(Produced, Rejected, RunTime, DownTime, Shift, ProducedDate, Line, EnteredDate) "
strSQL = strSQL & "VALUES('"&intProduced&"', "
strSQL = strSQL & '"&intRejected&"', '"&intRunTime&"', "
strSQL = strSQL & '"&intDownTime&"', '"&strShift&"', "
strSQL = strSQL & '"&datDateTimeField&"', '"&strLine&"', "
strSQL = strSQL & '"&GetDate()&"'); "
 
oops...missed quotes
Code:
strSQL = "INSERT INTO Bliss1TPM(Produced, Rejected, RunTime, DownTime, Shift, ProducedDate, Line, EnteredDate) "
strSQL = strSQL & "VALUES('"&intProduced&"', "
strSQL = strSQL & " '"&intRejected&"', '"&intRunTime&"', "
strSQL = strSQL & " '"&intDownTime&"', '"&strShift&"', "
strSQL = strSQL &  " '"&datDateTimeField&"', '"&strLine&"', "
strSQL = strSQL & " '"&GetDate()&"'); "

-L
 
Sorry L
I had to step away for minute

the error now is: Type mismatch

I'm a bit confused. What other info could I provide to help

Dave
 
ok Do a response.Write(strsQL)

and copy the output and run in the analyzer...

-L
 
I tried that and It's not writing the statement.
Same error.
here's the bulk of my code:

<%option explicit%>

<%
Dim DbConn

Const DATE_DELIMITER = "'"

Dim strSQL
Dim lngRecsAffected ' # of records affected

Dim intProduced
Dim strShift
Dim intRejected
Dim intRunTime
Dim intDownTime
Dim datDateTimeField
Dim strLine
Dim EnteredDate
Dim GetDate
Dim strErrorMsg ' Holds error message .


If Request.Form("action") <> "Save Form Data" Then
' Show the form
%>
<form action="<%=Request.ServerVariables("SCRIPT_NAME") %>" method="POST" name="FrontPage_Form1">
<input type="hidden" name="action" value="Save Form Data" />

'Form textbox info... I didn't think you need!

Else
' Do DB insert!

strLine = Request.Form("Line")
intProduced = Request.Form("Produced")
intRejected = Request.Form("Rejected")
intRunTime = Request.Form("RunTime")
intDownTime = Request.Form("DownTime")
strShift = Request.Form("Shift")
datDateTimeField = Request.Form("ProducedDate")


'Some datatype error handling of which I don't think you need

strSQL = "INSERT INTO Bliss1TPM(Produced, Rejected, RunTime, DownTime, Shift, ProducedDate, Line, EnteredDate) "
strSQL = strSQL & "VALUES('"&intProduced&"', "
strSQL = strSQL & " '"&intRejected&"', '"&intRunTime&"', "
strSQL = strSQL & " '"&intDownTime&"', '"&strShift&"', "
strSQL = strSQL & " '"&datDateTimeField&"', '"&strLine&"', "
strSQL = strSQL & " '"&GetDate()&"'); "


'response.write (strSQL)
' to test SQL statement

DbConn.Execute strSQL, lngRecsAffected

' Dispose of the CONN object
DbConn.Close
Set DbConn = Nothing

' Display a verification message and we're done!
%></FONT>
<div style="position: absolute; left: 188; top: 339; width: 900; height: 64">
<h2><font face="Arial">Thanks for submitting your Production Information for Bliss Line #1!</font></h2>

<p>
<font face="Arial">
<strong>Number of records affected:</strong> <FONT color=#0000ff><%= lngRecsAffected %></FONT>
</font>
</p>
</div>
<FONT color=#0000ff>
<%End If%>
<%End If%>
</FONT>

 
Thanks R937
I removed the quotes around

now looks like:
strSQL = strSQL & " '&GetDate()&'); "

error:
Syntax error converting datetime from character string
 
response.write worked this time

INSERT INTO Bliss1TPM(Produced, Rejected, RunTime, DownTime, Shift, ProducedDate, Line, EnteredDate) VALUES('2000', '2', '3', '0', '1st', '1/7/05', 'Bliss 1', '&GetDate()&');

Syntax error converting datetime from character string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top