Click to See Complete Forum and Search --> : Current Date into Access


myself1
06-04-2006, 03:51 PM
Hello all,
How can I get the current/registration date from a form to the DB?
(The form does not have a date field by the way)
It's sounds straight fwd but, my mind seems to have gone blank. :o

Most appreciated.

vanny
06-04-2006, 06:41 PM
There are a couple of ways in the form you can store the time in a hidden field when the form loads

<INPUT TYPE="hidden" NAME="strDate" VALUE="<%=NOW()%>">

However if you to go down this path then when you are storing it into the database you could just set the date field you have create to the value of NOW().

The biggest issue you have to look at here is that NOW() requests server time, if you went down a client side javascript current time method into a hidden field, then you would be getting the local machines date and time, which could be totally different to your servers.

Hope this helps.

myself1
06-05-2006, 01:53 AM
Thank you for the reply. Basically I am only interested in the date (not time).

Will this script:

<INPUT TYPE="hidden" NAME="strDate" VALUE="<%=NOW()%>">

provide the date the user registered?
Thanks again.

russell
06-05-2006, 11:17 AM
You should just do it server side. When you do the db insert, populate the field with Date(). Don't put a hidden form element -- these can be modified by the user. Also, you're writing extra code that is unnecessary if you do that. Some databases allow default constraints as well that you can set to automatically put the current date in the field when the other fields are populated. What db are you using?

myself1
06-05-2006, 03:52 PM
DB I'm using is Access.

As people register their interest on the web form, will Access automatically add the current date of the entry, with the field set as Date()?

russell
06-05-2006, 04:35 PM
Use the MS Access Date() Function

INSERT INTO myTable (userName, dt)
VALUES ('Russell', Date())

myself1
06-13-2006, 03:17 AM
In the following code:

wpage = LCase(request.ServerVariables("HTTP_REFERER"))
If InStr(1,wpage,"form1.asp") Then
mySQL = "INSERT INTO tbl_team (tName, tSurname, tAge")
mySQL = mySQL & " VALUES ('" & request.form("tName") & "','" & request.form("tSurname") & "','" & request.form("tAge") & "')"
ELSE
mySQL = "INSERT INTO tbl_help (hName, hSurname, hAge")
mySQL = mySQL & " VALUES ('" & request.form("hName") & "','" & request.form("hSurname") & "','" & request.form("hAge") & "')"
End if
myCon.execute(mySQL)

where do I insert the date element? In both statements or can I insert it as one variable?

Hope to hear...