Working with Dates

You can use dates that are associated with an item in various ways.

You can, of course, display dates. Unlike text fields, dates are stored in an internal format that understands that it is a date, so you can choose the format when you display a date. (See Formatting Dates for details.)

You can also use dates as conditions, and there is a special value "now", which is just what you'd expect. The following example shows all events with a start_date after today:


<w:kb:item:each type='event' condition='start_date > now' sort='start_date'>

  <h2><w:name /></h2>

</w:kb:item:each>

You can also use dates in stand-alone conditionals. This code displays all events but adds "(Past)" after an event whose date is past:


<w:kb:item:each type='event' sort='start_date'>

  <h2><w:name /><w:if condition='start_date < now' > (Past)</w:if></h2>

</w:kb:item:each>

There's also a date setting that automatically affects visibility of items. If you set the Published At date after the current date, then the item will not appear until that date arrives. (The Published At field is included on all standard item types, and you can choose to include it or not on custom item types.)

Selecting Items Based on Date

You can use any of the usual comparison operators: <, >, !=, =, >=, and <= .

The value that you compare against can be, as in the example above, "now", which is the current date and time. You can also compare to a date, formatted as YYYY-MM-DD, or a date and time, formatted as YYYY-MM-DD HH:MM. For example,


condition = "start_date >= 2010-01-01"

selects items that start after the first of January 2010.

If you want to get fancy, you can also write simple date equations, and Webvanta understands days, hours, and minutes. So you can write:


condition = "start_date >= now + 3.days

which specifies that the start date is greater than or equal to three days from now. Note the use of the period, with no spaces, to separate the number from the time unit (days, hours, or minutes).

Simple Date-Based Conditionals

The w:if and w:unless statements accept only a few simple conditions. You can use any of the comparison operators, but you can only compare against "now". For example,


<w:if condition = "start_date > now">

   (use this code only if the start date is in future)

</w:if>