There are two ways to achieve this. Form script will vary depending on the type of form control used to display the date and when you want to populate the date. The examples below (also the attachment) show how to use either a DynamicLabel or a TextField to populate the date when the form opens.
To use either method, open the Script Editor.
- Double-click the AfterOpen event.
- Use a Text Field: add the following to AfterOpen
-
When using a TextField, it is best to specify the date format as defined in the TextField Field Properties>Layout >Date Format. This ensures the date will be populated in the field properly. If you specify MM/dd/yyyy the population will fail.
_DynamicLabel_1.Value = Today().ToString(_Date_1.DateTimeFormat)
2. Use a Dynamic Label: add the following line of code to AfterOpen
_DynamicLabel_2.Value = Today().ToString("dd/MMM/yy")
- We can also specify any valid .NET DateTime formatting. In the example above we are using the dd/MMM/yy, we might just easily specify it as MM/dd/yyyy
_DynamicLabel_3.Value = Now().ToString("MM/dd/yyyy")
If you would like to populate the time along with the date, instead of using Today(), use Now().
- You will need to add additional formatting for the time when using a DynamicLabel. For example:
_DynamicLabel_4.Value = Now().ToString("MM/dd/yyyy HH:mm:ss")
- TextFields should still use the _MyField.DateTime Format and change the Date Format in TextField Field Properties to MM/dd/yyyy HH:mm