On 04/02/2010 06:55, hemanth reddy wrote:
> can i do it using [%USE Date%]?

No, I don't think you can.

However you might like to take a look at Badger::Timestamp.  This does
more-or-less everything that the date plugin does, but without being
specifically tied in to TT.  Badger::Timestamp is descended from the
date plugin and will replace it in TT3 (i.e. Template::Plugin::Timestamp
will be a TT plugin shaped wrapper around Badger::Timestamp).  So in that
sense, Badger::Timestamp is the new Template::Plugin::Date.

   http://badgerpower.com/docs/Badger/Timestamp.html

If you want to do anything more complicated than what Badger::Timestamp
provides then DateTime is almost certainly the answer.

Pasted below is an example of using B::T with T::T.

BTW, I just discovered that the version of Badger::Timestamp on CPAN (Badger
0.06) doesn't accept a single digit hour, e.g. '2000/12/21 4:20:36'.  I just
checked in a fix for that, so you might want to grab the latest version from
git:

   http://github.com/abw/Badger

Cheers
A


#!/usr/bin/perl
#
# Perl script to demonstrate Badger::Timestamp
#
# Written by Andy Wardley http://wardley.org/
#
# 10 June 2009
#

use Template;
use Badger::Timestamp;

my $tt   = Template->new;
my $vars = {
     stamp => sub { Badger::Timestamp->new(@_) }
};

$tt->process(\*DATA,  $vars)
     || die $tt->error;


__END__
[% # you can pass a timestamp argument
    t = stamp('2009-06-10 16:29:04')
%]
timestamp: [% t %]
date: [% t.date %]
time: [% t.time %]
hour: [% t.hour %]
epoch time: [% t.epoch_time %]

[% # or you get the current time %]
The current time is [% stamp %]

[% # you can adjust a timestamp to change the time/date %]
[% ago4 = stamp.adjust( minutes = -4 ) -%]
4 minutes ago the time was [% ago4.time %]
[% ago5 = stamp.adjust( minutes = -5 ) -%]
5 minutes ago the time was [% ago5.time %]
[% ago6 = stamp.adjust( minutes = -6 ) -%]
6 minutes ago the time was [% ago6.time %]

[% # before() and after() allow you to compare timestamps %]
Is [% ago4 %] before 5 minutes ago? [% ago4.before(ago5) ? 'YES' : 'NO' %]
Is [% ago6 %] before 5 minutes ago? [% ago6.before(ago5) ? 'YES' : 'NO' %]

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to