How to include the current date in an insert page

There are different ways to include the current date in a newly inserted record. This TechNote describes two options:

  1. Using hidden fields with ColdFusion, PHP, ASP, ASP.NET or JSP code.
  2. Setting the default value for the database field equal to the current date.

Hidden form fields

One approach to this task is to setup a hidden field (Insert> Form > Hidden Field). Once the hidden field has been added, select the yellow icon that represents the hidden field and go to the Property inspector. In the Value field, enter the appropriate code for the date function:

  • ASP: <%= Date() %>
  • JSP: <%= new java.util.Date() %>
  • ColdFusion: #Now()#

If you want to give the end user the option to change the date to something other than today's date, then use a regular text field instead of a hidden field.

When filling out the Insert Record server behavior dialog box, map the hidden form field to the date field in the database and set the data type to either "Date" or "MS Access Date".

Note: The date being inserted will be the date on the application server. Keep this in mind if users are in different time zones.

Setting the default value in the database

Another approach to this task is to set the default value of the database's date field to the current system date. Most, if not all, databases will have a "default value" option for database fields. One advantage to using this approach is that you do not have to worry about the date format being sent from the web page. Here is how to set the default value to today's date in Microsoft Access 2000:

  1. Open the database in Microsoft Access.
  2. Open the database table in Design view, and select the date field.
  3. Go to the General tab in the bottom section of the window and type "Date()" (no quotes) in the Default Value field.

  4. Save and close the database, and go back to Dreamweaver to finish the insert page.
  5. When filling out the Insert Record server behavior dialog box in Dreamweaver, you will not map a form field to the date field in the database. The database will automatically fill in the current date when a new record is created.

Please refer to the Microsoft Access documentation for further detail on setting default values. If you are not using Access, please refer to your database documentation for instructions on how to set the default date value.

Note: The date being inserted will be the date on the database server. Keep this in mind if users are in different time zones.

Additional information

For more information on how to use the Insert Record server behavior, please see Building an insert record page block by block.

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online