Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


As a rule of thumb, always pass dates to Smarty as timestamps. This allows template designers to use the date_format modifier for full control over date formatting, and also makes it easy to compare dates if necessary.

Example 272. Using date_format



This will output:

Jan 4, 2009




This will output:



Dates can be compared in the template by timestamps with:

{if $order_date < $invoice_date} something..


When using {html_select_date} in a template, the programmer will most likely want to convert the output from the form back into timestamp format. Here is a function to help you with that.

Example 273. Converting form date elements back to a timestamp


// this assumes your form elements are named
// startDate_Day, startDate_Month, startDate_Year

$startDate makeTimeStamp($startDate_Year$startDate_Month$startDate_Day);

$year)) {
$year strftime('%Y');
$month)) {
$month strftime('%m');
$day)) {
$day strftime('%d');



See also {html_select_date}, {html_select_time}, date_format and $,

Smarty Template Engine