date_format

date_format — This formats a date and time into the given strftime() format. Dates can be passed to Smarty as unix timestamps, mysql timestamps or any string made up of month day year, parsable by php's strtotime(). Designers can then use date_format to have complete control of the formatting of the date. If the date passed to date_format is empty and a second parameter is passed, that will be used as the date to format.

  • value: the date, as a unix timestamp, mysql datetime or whatever strtotime() can parse
  • format: output format, see http://php.net/strftime for details
  • default: a default timestamp value, if the first one is empty
if your current PHP 7.0 then strftime function used for date formatting

This template uses $.now to get the current time:


<?php
$config['date'] = '%I:%M %p';
$config['time'] = '%H:%M:%S';
$Tplix->assign('config', $config);
$Tplix->assign('yesterday', strtotime('-1 day'));
?>
    
Examples:

This template uses $.now to get the current time:


{$.now|date_format}
{$.now|date_format:"%D"}
{$yesterday|date_format:$config.date} 
{$yesterday|date_format:"%A, %B %e, %Y"}
{$yesterday|date_format:$config.time} 
    

The above example will output:


Jan 1, 2022
01/01/22
02:33 pm
Dec 31, 2021
Monday, December 1, 2021
14:33:00