Date & time formatting in variables

<< Click to Display Table of Contents >>

Navigation:  Reference > Modules, Conditional Output & Variables > Variables and Conditional Output >

Date & time formatting in variables

flag_green        Key Information

You can only use this option with the <%NOW%> variable.

If you need specific formatting for date and time in a variable you can achieve this with the <%NOW%> variable in combination with a special format string. This is the only variable that works like this. It is also the only one you need, since you can include any text and any number of date and time options in the same format string.

 

Basic syntax

To use this feature you insert the <%NOW%> variable in your project, either manually or with the Insert Variable tool, and then manually type a format string in parentheses inside the variable name in the Help+Manual editor:

<%NOW(format string)%>

Position and syntax of the format string:

The format string must be inserted in parentheses between last letter of the NOW name and the closing %> characters of the variable tag. The string can contain both "specifiers" that define the date and time format and normal text, which must be enclosed in double quotes.

Specifiers may be written in upper or lower case, the result will be the same.

Example:

<%NOW("This topic was last modified on " dddd, mmmm d, yyyy, " at " hh:mm AM/PM)%>

Example result: This topic was last modified on Tuesday, January 3, 2013, at 12:22 PM

The text within the quotes will be inserted exactly as it is written. Any spaces required must be included within the quotes and the quotes must be separated from the specifiers by spaces.

Date and time format specifiers

Specifier

Function

" text "

' text '

Anything enclosed in single or double quotes is inserted unchanged as plain text and does not affect formatting.

. and ,

You can include periods and commas in the formatting string with the specifiers, these characters to not need to be quoted.

c

Displays the date using the standard Windows short date format, followed by the time using the standard Windows long time format. The time is not displayed if the fractional part of the DateTime value is zero.

d

Displays the day of the month as a number without a leading zero (1-31).

dd

Displays the day of the month as a number with a leading zero (01-31).

ddd

Displays the day as an abbreviation (Sun-Sat) using the standard Windows strings for short day names.

dddd

Displays the day as a full name (Sunday-Saturday) using the standard Windows strings for full day names.

ddddd

Displays the date using the standard Windows short date format.

dddddd

Displays the date using the standard Windows long date format.

m

Displays the month as a number without a leading zero (1-12). If the m specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.

mm

Displays the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.

mmm

Displays the month as an abbreviation (Jan-Dec) using the standard Windows values for short month names.

mmmm

Displays the month as a full name (January-December) using the standard Windows values for long month names.

yy

Displays the year as a two-digit number (00-99).

yyyy

Displays the year as a four-digit number (0000-9999).

h

Displays the hour without a leading zero (0-23).

hh

Displays the hour with a leading zero (00-23).

n

Displays the minute without a leading zero (0-59).

nn

Displays the minute with a leading zero (00-59).

s

Displays the second without a leading zero (0-59).

ss

Displays the second with a leading zero (00-59).

z

Displays the millisecond without a leading zero (0-999).

zzz

Displays the millisecond with a leading zero (000-999).

t

Displays the time using the standard Windows short time format.

tt

Displays the time using the standard Windows long time format.

am/pm

Uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' for any hour before noon, and 'pm' for any hour after noon. The am/pm specifier can use lower, upper, or mixed case, and the result is displayed accordingly.

ampm

Uses the 12-hour clock for the preceding h or hh specifier, and displays the contents of the Windows TimeAMString global variable for any hour before noon, and the contents of the TimePMString global variable for any hour after noon.

/

Displays the date separator set in your Windows configuration.

:

Displays the time separator set in your Windows configuration.

See also:

Using Variables