Difficulty: ★☆☆ (easy)
Keywords: date and time, datetime, dbtimestamp, processing-instruction, context

Problem

You want to insert the current date, time, or both into your output format (for example, to show the date of creation).

Solution

Use the <?dbtimestamp?> processing instruction (PI). For example, integrate it into the pubdate to show the current publication date on the titlepage:

<info>
  <!-- ... -->
  <pubdate><?dbtimestamp?></pubdate>
</info>

Discussion

The above PI includes the date in its localized form, or in other words: the output depends on the current language. If you do not have set any language, the default is English (en_US) which is month/day/year. If you want to change the default format, use one of the two options:

  • Change the default format

  • Add pseudo-attributes

Changing the Default Format

Each language contains the context datetimein its language files add xref. The following code is from the English language file:

<l:context name="datetime">
  <l:template name="format" text="m/d/Y"/>
</l:context>

This is only useful, if you want to completely change the appearance of a date in your document.

Adding Pseudo-Attributes

The simpler method is to change the PI directly. Especially if you do not want to customize the date for the complete document or you want it change individually. Basically, add a pseudo-attribute[5] into the <?dbtimestamp?> PI. For example, if you want to insert the year only, add the format pseudo-attribute:

<?dbtimestamp format="Y"?>

More format-letters can be found in the reference page (see link in the See Also section).

See Also


[5] A pseudo-attribute looks like an XML attribute due to its similar syntax. However, it is not. A processing instruction can only contain text and no attributes. For more information about PIs, refer to the XML specification at http://www.w3.org/TR/REC-xml/#sec-pi.


Project@GitHubIssue#7