---
name: "Template::Plugin::DateTime"
section: "3pm"
platform: "linux"
package: "libtemplate-plugin-datetime-perl"
version: "0.06002-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Template::Plugin::DateTime"
---

# Template::Plugin::DateTime(3pm)

A Template Plugin To Use DateTime Objects

## NAME

Template::Plugin::DateTime - A Template Plugin To Use DateTime Objects

## SYNOPSIS

```
  [% USE date = DateTime(year = 2004, month = 4, day = 1) %]
  [% USE date = DateTime(today = 1) %]
  Today is [% date.year %]/[% date.month %]/[% date.day %].
  [% date.add(days => 32) %]
  32 days from today is [% date.year %]/[% date.month %]/[% date.day %].
```

## DESCRIPTION

The basic idea to use a DateTime plugin is as follows:

```
  USE date = DateTime(year = 2004, month = 4, day = 1);
```

\-OR-

by passing a pattern to parse a date by string using DateTime::Format::Strptime

```
        USE date = DateTime(from_string => '2008-05-30 00:00:00', pattern => '%Y-%m-%d %H:%M:%S', time_zone => 'America/New_York');
```

## METHODS

### new

This is used internally. You won't be using it from your templates.

## CONSTRUCTOR

The constructor is exactly the same as that of Datetime.pm, except you can pass optional parameters to it to toggle between different underlying DateTime constructors.

- from\_epoch

  Creates a Datetime object by calling **DateTime::from\_epoch()**. The value for the from\_epoch parameter must be a number representing UNIX epoch.

  ```
    [% epoch = ...  %]
    [% USE date = DateTime(from_epoch = epoch) %]
  ```

- now

  Creates a DateTime object by calling **DateTime::now()**. The value for the c\<now\> parameter is a boolean value.

  ```
    [% USE date = DateTime(now = 1) %]
    [% USE date = Datetime(now = 1, time_zone => 'Asia/Tokyo') %]
  ```

- today

  Creates a DateTime object by calling **DateTime::today()**. The value for the c\<today\> parameter is a boolean value.

  ```
    [% USE date = DateTime(today = 1) %]
  ```

- from\_object

  Creates a DateTime object by calling **DateTime::from\_object()**. The value for the from\_object must be an object implementing the **utc\_rd\_values()** method, as described in DateTime.pm

  ```
    [% USE date = DateTime(from_object = other_date) %]
  ```

- last\_day\_of\_month

  Creates a DateTime object by calling **DateTime::last\_day\_of\_month()**. The value for the c\<last\_day\_of\_month\> parameter is a boolean value, and `"year"` and `"month"` parameters must be specified.

  ```
    [% USE date = DateTime(last_day_of_month = 1, year = 2004, month = 4 ) %]
  ```

- from\_string

  Creates a DateTime object by calling DateTime::Format::Strptime The value for the c\<from\_string\> parameter is a string value, and `"pattern"` parameters is optional and defaults to '%Y-%m-%d `%H:`%M:%S'.  See DateTime::Format::Strptime for other optional parameters.

  ```
    [% USE date = DateTime(from_string => '2008-05-30 10:00:00', pattern => '%Y-%m-%d %H:%M:%S') %]
  ```

## SEE ALSO

DateTime DateTime::Format::Strptime Template

## AUTHOR

Copyright (c) 2004-2007 Daisuke Maki \<daisuke@endeworks.jp\>.

## LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html
