---
name: "Catmandu::Plugin::Datestamps"
section: "3pm"
platform: "linux"
package: "libcatmandu-perl"
version: "1.2024-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Catmandu::Plugin::Datestamps"
---

# Catmandu::Plugin::Datestamps(3pm)

Automatically add datestamps to Catmandu::Store records

## NAME

Catmandu::Plugin::Datestamps - Automatically add datestamps to Catmandu::Store records

## SYNOPSIS

```
 # Using configuration files
 $ cat catmandu.yml
 ---
 store:
  test:
    package: MongoDB
    options:
      database_name: test
      bags:
        data:
          plugins:
            - Datestamps
 $ echo '{"hello":"world"}' | catmandu import JSON to test
 $ catmandu export test to YAML
 ---
 _id: ADA305D8-697D-11E3-B0C3-97AD572FA7E3
 date_created: 2013-12-20T13:50:25Z
 date_updated: 2013-12-20T13:50:25Z
 hello: world
 # Or in your Perl program
 my $store = Catmandu::Store::MongoDB->new(
            database_name => 'test' ,
            bags => {
                data => {
                plugins => [qw(Datestamps)]
            }
        });
 $store->bag->add({
        '_id'  => '123',
        'name' => 'John Doe'
 });
 my $obj = $store->bag->get('123');
 print "%s created at %s\n" , $obj->{name} , $obj->{date_created};
```

## DESCRIPTION

The Catmandu::Plugin::Datestamps plugin automatically adds/updates datestamp fields in your records. If you add this plugin to your Catmandu::Store configuration then automatically a  'date\_created' and 'date\_updated' field gets added to newly ingested records.

The plugin should be set for every bag defined in your Catmandu::Store. In the examples above we've set the plugin to the default bag 'data' that is created in every Catmandu::Store.

In Catmandu::Store-s that don't have a dynamic schema (e.g. Solr, DBI) these new date fields should be predefined (e.g by changing the schema.xml or tables fields).

## CONFIGURATION

- datestamp\_created\_key

  Field name where the creation date is stored. Defaults to 'date\_created'. Also aliased as `"datestamp_created_field"`.

- datestamp\_updated\_key

  Field name where the update date is stored. Defaults to 'date\_updated'. Also aliased as `"datestamp_updated_field"`.

- datestamp\_format

  Use a custom `"strftime"` format. See Catmandu::Util::now for possible format values.

  ```
      my $store = Catmandu::Store::MyDB->new(bags => {book => {plugins =>
          ['Datestamps'], datestamp_format => '%Y/%m/%d'}});
      my $store = Catmandu::Store::MyDB->new(bags => {book => {plugins =>
          ['Datestamps'], datestamp_format => 'iso_date_time_millis'}});
  ```

## SEE ALSO

Catmandu::Store, Catmandu::Bag
