You are here: Message Personalization and Scripting > Mail Merge > How To Format Dates

How do I convert dates into a useful format?

 

Sometimes, you will want to change the format of a date into a more human-readable format, instead of using the default format. You can do this using the "timeformat" mail merge tag. The syntax is:

 

%%timeformat tablename.datefield "formatstring"%%


datefield refers to any date field in the table tablename. Formatstring refers to a sequence of codes which tell ListManager how to display the date. A list of these codes is below.

 

If the "formatstring" argument is not specified, the format string "%a %b %d %H:%M:%S %Z %Y" is used (e.g.: "Fri Mar 01 15:40:00 PDT 2002").

 

Format Codes

Field descriptors consist of a % followed by a field descriptor character. All other characters are copied into the result. Valid field descriptors are:

%%
Insert a %.

%a
Abbreviated weekday name (Mon, Tue, etc.).

%A
Full weekday name (Monday, Tuesday, etc.).

%b
Abbreviated month name (Jan, Feb, etc.).

%B
Full month name.

%c
Locale specific date and time.

%d
Day of month (01 - 31).

%H
Hour in 24-hour format (00 - 23).

%I
Hour in 12-hour format (00 - 12).

%j
Day of year (001 - 366).

%m
Month number (01 - 12).

%M
Minute (00 - 59).

%p
AM/PM indicator.

%S
Seconds (00 - 59).

%U
Week of year (00 - 52), Sunday is the first day of the week.

%w
Weekday number (Sunday = 0).

%W
Week of year (00 - 52), Monday is the first day of the week.

%x
Locale specific date format.

%X
Locale specific time format.

%y
Year without century (00 - 99).

%Y
Year with century (e.g. 1990)

%Z
Time zone name.


The -gmt option to the clock command

If the -gmt argument is present the next argument must be a boolean which if true specifies that the time will be recalculated as Greenwich Mean Time. If false then the local time zone will be used as defined by the operating environment. If the -gmt option is not specified, then the local time zone time will be used.

 

Examples

Suppose the value of the date field DateJoined_ is Friday, March 1, 2002 at 3:40 P.M., and your server is in California.

 

%%timeformat members_.Datejoined_%%

 

would print: Fri Mar 01 15:40:00 PDT 2002
 

%%timeformat members_.DateJoined_ "%A, %B %d, %Y %I:%M %p"%%

 

would print: Friday, March 01, 2002 03:40 P.M.

 

%%timeformat members_.DateJoined_ "%a %d %b %Y %H:%M"%%

 

would print: Fri 01 Mar 2002 15:40

 

%%timeformat members_.DateJoined_ "%m/%d/%y %H:%M:%S"%%

 

would print: 03/01/02 15:40:00

 

%%timeformat members_.DateJoined_ "%m/%d"%%

 

would print: 03/01

 

%%return [clock format [clock seconds] -format "%A %b %d, %Y"]%%

 

would print the date when the particular message is sent, based on the system time.

 

Example:

 

Friday August 2, 2002

 

 More

 

Using Mail Merge Tags

Mail Merge Short Tags

How To Format Dates

Fetching Data from a Web Server

Troubleshooting Merge Tag Problems