Customising date formatting when using environment variables
Who is this article for?
Users looking to pull information from system fields into documents or emails.
No special access or permissions are required.
To dynamically update documents, emails, and workflows when an item is opened or crated, you can use system-specific fields, also known as environment variables.
One such variable type is a date or date time variable. By default, this displays in the following format: 'Wednesday, April 07, 2004 11:31:22 AM'.
This article shows you how you can customise the display by manipulating the field properties.
1. Customising date formatting
To customise the display:
- Switch to the Insert tab.
- Click Quick Parts.
- Select Field....
If you already have a date field included, right-click it and select Edit Field. - Choose DocProperty from Field names.
- Highlight a date field from the list on the right.
- Click the Field Codes button.
- Add '\@' and a formatting code from the field codes table to the end of the Field codes line.
- Click OK.
Your date field will be updated with the new format.
2. List of field codes
2.1. Field codes
| Code | Example | Example result |
| MM/DD/YYYY | ##DATE_PUBLISHED## \@ MM/DD/YYYY | 02/06/2011 |
| M/D/YYYY | ##DATE_PUBLISHED## \@ M/D/YYYY | 2/6/2011 |
| "DDD M/D/YYYY"* | ##DATE_PUBLISHED## \@ "DDD M/D/YYYY" | Fri 2/6/2011 |
| "DDDD MMMM D, YYYY" | ##DATE_PUBLISHED## \@ "DDDD MMMM D, YYYY" | Friday February 6, 2011 |
*If the code contains any spaces, enclose all of it in full quotation marks.
2.2. Field code parameters
Year
Displays a year as two or four digits, depending on how many letter "y"s you use. The letter "y" can be either uppercase or lowercase.
| Parameter | Description | Example |
| y or yy | Year in two-digit form, with a leading 0 for years 00 to 09. | 06 or 98 |
| yyyy | Year in four-digit form. | 2006 |
Month
Displays a month as one or two digits, as an abbreviation or in full, depending on how many uppercase letter "M"s you use (lowercase letter "m" represents minutes).
| Parameter | Description | Example |
| M | Month as a number without a leading 0 for single-digit months. | 7 |
| MM | Month as a two-digit number with a leading 0 for single-digit months. | 07 |
| MMM | Month as a three-letter abbreviation. | Jul |
| MMMM | Month as a full name. | July |
Day
Displays a day of the month or the day of the week, depending on how many letter "d"s you use. The letter "d" can be either uppercase or lowercase.
| Parameter | Description | Example |
| d | Day of the month as a number without a leading 0 for single-digit days. | 7 or 27 |
| dd | Day of the month as a number with a leading 0 for single-digit days. | 07 or 27 |
| ddd | Day as a three letter abbreviation. | Thu |
| dddd | Day as a full name. | Thursday |
Hour
Displays an hour of the day as one or two digits based on either a 12-hour clock or a 24-hour (military) clock, depending on whether you use an uppercase or lowercase "h". A lowercase "h" bases time on the 12-hour clock. An uppercase "H" bases time on the 24-hour (military) clock. You can also include "AM/PM" in uppercase or lowercase.
| Parameter | Description | Example |
| h or H | Hours as a number without a leading 0 for single-digit days. | 8 or 20 |
| hh or HH | Hours as a number with a leading 0 for single-digit days. | 08 or 20 |
| am/pm | Morning hours or evening hours. | AM |
You can change the AM and PM symbols that Word uses by changing the Regional Settings in the Windows Control Panel. For example, you could use this to force the "am/pm" parameter to display as "a.m./p.m.".
Minute
Displays the minute as one or two digits, depending on how many letter "m"s you use (uppercase letter "M" represents months).
| Parameter | Description | Example |
| m | Minutes as a number without a leading 0 for single-digit days. | 8 or 48 |
| mm | Minutes as a number with a leading 0 for single-digit days. | 08 or 48 |
Second
Displays the number of seconds as one or two digits, depending on whether you type the letter "s" once or twice. The letter "s" can be either uppercase or lowercase.
| Parameter | Description | Example |
| s | Seconds as a number without a leading 0 for single-digit days. | 6 or 16 |
| ss | Seconds as a number with a leading 0 for single-digit days. | 06 or 16 |