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

Note: As of Smarty 1.4.0, you can pass dates to Smarty as unix timestamps, mysql timestamps, or any date parsable by strtotime().

Example 18-4. using date_format


This will output:

Jan 4, 2001

This will output:

{if $date1 < $date2}

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 18-5. 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 $,

© Copyright 2003-2023 The ultimate PHP Editor and PHP IDE site.