Calendar:Date template tag

Calendar:Date is useful for situations where you want to output formatted date data for any arbitrary date. So, you would typically use this in these three circumstances:

  1. you need full date formatting for a some random date.
  2. you want to find out information about a date that falls relative to some other date.
  3. you need to turn date segments into a formattable date in your template (Calendar-related or not).

The advantage is that you can format the outgoing date however you please. Since this function uses Calendar’s powerful date parameters you can not only output absolute dates (ex: 2010-04-15), you can also output relative dates (ex: "-2 weeks begin"). Even better, using the base_date="" parameter, the dates can be relative to ANY date, not just today.

{exp:calendar:date} content {/exp:calendar:date}
1

Parameters

base_date=

base_date="2009-06-01"

The base date for relative date calculations. Both standard and easy-to-use text date formatting apply to this parameter. Only relevant if the output_date parameter is set to a relative value (ex: -1 week). Default is equivalent to today @ now.

output_date=

output_date="2010-06-last"

The date you want to display. Both standard and easy-to-use text date formatting apply to this parameter. If the value is a relative date, the date will be relative to the value of base_date.

Variables

date

{date format="%Y-%m-%d"}

The date as determined by the output_date parameter. If format is not specified the format defaults to %Y%m%d (ex: 20100415).

base_date

{base_date format="%Y-%m-%d"}

The base date as set in the base_date parameter. If format is not specified the format defaults to %Y%m%d (ex: 20100415).

Examples

The following example is how you would generate tomorrow‘s date:

{exp:calendar:date
  base_date="today"
  output_date="tomorrow"
}
  <p>Weather forecast for Tomorrow ({date format="%F %j, %Y"})</p>
{/exp:calendar:date}
1
2
3
4
5
6

Or, 1 year from tomorrow‘s date would be done like this:

{exp:calendar:date
  base_date="tomorrow"
  output_date="1 year"
}
  <p>1 Year from Tomorrow would be {date format="%F %j, %Y"}.</p>
{/exp:calendar:date}
1
2
3
4
5
6

If you've ever needed to turn date segments in the URL into a formattable date in your template, this is the perfect tag to use (Calendar related or not):

{exp:calendar:date
  base_date="{segment_3}-{segment_4}-{segment_5}"
  output_date="today"
}
  {date format="%F %j, %Y"}
{/exp:calendar:date}
1
2
3
4
5
6