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 are special values of "now" and "time_now". "Now" represents the current date where the time is set to midnight while "time_now" represents the current date + the current time.

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>

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>

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)