Time-stamping records in a database as they are being inserted is a common practice in dynamic Web development. You may find it useful when examining the traffic patterns of your website or quantifying the reaction to a marketing campaign. Inserting the current time of day into a ColdFusion database is a simple matter, as one of ColdFusion's built-in functions returns the current date and time of the computer running the ColdFusion server, and can be formatted to display only the time.
Instructions
- 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.
2Open the page that is currently inserting records into the table in question. Move the cursor to the
INSERT INTO Employees
(FirstName, LastName, Email, Phone, Department)
VALUES (firstname, lastname, email, phone, department)
3Add 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
INSERT INTO Employees
(FirstName, LastName, Email, Phone, Department, CurrentTime)
VALUES (firstname, lastname, email, phone, department, TimeFormat(Now()))
This will insert the current time into the new database record along with the rest of the variables.
4Save and publish your Web page.
0 comments:
Post a Comment