Dates can be printed with fmt
by using the %at
format.
The t
code indicates a time is being printed, and the a
flag indicates that the next argument is a
strftime()
-style format string. Following that
is a time argument. Example: <fmt "%at" "%B" "now">
where
"%B"
is the strftime()
-style string (indicating the
month should be printed). A capital T
may be used instead of
lower-case t
to change the timezone to Universal Time (GMT/UTC)
instead of local time for output. These strftime()
codes are
available:
%a
for the abbreviated weekday name (e.g. Sun
, Mon
,
Tue
, etc.)%A
for the full weekday name (e.g. Sunday
, Monday
,
Tuesday
, etc.)%b
for the abbreviated month name (e.g. Jan
, Feb
,
Mar
, etc.)%B
for the full month name (e.g. January
, February
,
March
, etc.)%c
for the preferred date and time representation.%d
for the day of the month as a decimal number (range 01
through 31
).%H
for the hour as a decimal number using a 24-hour clock (range
00
through 23
).%I
for the hour as a decimal number using a 12-hour clock (range
01
through 12
).%j
for the day of the year as a decimal number (range 001
through
366
).%m
for the month as a decimal number (range 01
through 12
).%M
for the minute as a decimal number (range 00
through 59
).%p
for AM
or PM
, depending on the time.%S
for the second as a decimal number (range 00
through 60
;
60 to allow for possible leap second if implemented).%U
for the week number of the current year as a decimal number, starting
with the first Sunday as the first day of the first week (range
00
through 53
).%W
for the week number of the current year as a decimal number, starting
with the first Monday as the first day of the first week (range
00
through 53
).%w
for the day of the week as a decimal, Sunday being 0.%x
for the preferred date representation without the time.%X
for the preferred time representation without the date.%y
for the year as a decimal number without a century (range 00
through 99
).%Y
for the year as a decimal number including the century.%Z
for the time zone or name or abbreviation.%%
for a literal `%
' character.
Since fmt
arguments are typecast if needed
(here), the date argument can be a Texis
date
or counter
type, or a Texis-parseable date string.
For example, to print today's date in the form month/day/year:
<fmt "%at" "%m/%d/%y" "now">
Or to print the title and insertion date of books matching a query,
in the style "February 20, 1997
" (assuming id
is a
Texis counter
field):
<SQL "select id, Title from books where Desc like $query">
<fmt "%at" "%B %d, %Y" $id> $Title
</SQL>
If the strftime()
string is composed entirely of
strftime()
-specific codes, none of which have meaning as
<fmt>
codes, and there is only one argument given, then the
initial %at
may be omitted. For example, to print today's
year, either of these statements may be used:
<fmt "%at" "%Y" "now">
<fmt "%Y" "now">
The second statement eliminates the %at
, because %Y
is a
strftime()
-only code (not valid in <fmt>
). Note:
Due to potential confusion and conflicts between strftime()
and
<fmt>
codes - especially as more codes/flags are added to the
latter - use of this shorthand is discouraged. Always use the
a
flag and a t
or T
code.
To use a default strftime()
format, eliminate the a
flag and its corresponding strftime()
format argument:
<fmt "%t" "now">
This will print today's date in a default format.
CAVEATS
As dates are printed using the standard C
library, not all
strftime()
codes are available or behave identically on all
platforms.