Comunitatea PHP Romania
 

 
Dates

Dates

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 18-4. Using date_format

{$startDate|date_format}

This will output:

Jan 4, 2009
{$startDate|date_format:"%Y/%m/%d"}

This will output:

2009/01/04

Dates can be compared in the template by timestamps with:

{if $order_date < $invoice_date}
   ...do something..
{/if}

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

<?php

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

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

function 
makeTimeStamp($year=''$month=''$day='')
{
   if(empty(
$year)) {
       
$year strftime('%Y');
   }
   if(empty(
$month)) {
       
$month strftime('%m');
   }
   if(empty(
$day)) {
       
$day strftime('%d');
   }

   return 
mktime(000$month$day$year);
}
?>

See also {html_select_date}, {html_select_time}, date_format and $smarty.now,

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
la birou
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Credit Report | eHarmony | Loans | Loans | Advertising
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis