How to Insert Time in ColdFusion
- 1). Create a new column in the table in which you wish to insert time values into your records. Give it a name that you will remember later. As an example, assume the new column name is CurrentTime.
- 2). Open the page that is currently inserting records into the table in question. Move the cursor to the <cfquery> tag that is inserting them. For the above example, assume the <cfquery> statement reads as follows:
<cfquery name="AddEmployee" datasource="cfdocexamples">
INSERT INTO Employees
(FirstName, LastName, Email, Phone, Department)
VALUES (#firstname#, #lastname#, #email#, #phone#, #department#)
</cfquery> - 3). Add your new column heading from Step 1 to the list of column headings after the table name and a value of #Now()# into the list of values. For the above example, you would change the <cfquery> tag to the following:
<cfquery name="AddEmployee" datasource="cfdocexamples">
INSERT INTO Employees
(FirstName, LastName, Email, Phone, Department, CurrentTime)
VALUES (#firstname#, #lastname#, #email#, #phone#, #department#, #TimeFormat(Now())#)
</cfquery>
This will insert the current time into the new database record along with the rest of the variables. - 4). Save and publish your Web page.
Source...