---
name: "Data::Faker::DateTime"
section: "3pm"
platform: "linux"
package: "libdata-faker-perl"
version: "0.10-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Data::Faker::DateTime"
---

# Data::Faker::DateTime(3pm)

Data::Faker plugin

## NAME

Data::Faker::DateTime - Data::Faker plugin

## SYNOPSIS AND USAGE

See Data::Faker

## DATA PROVIDERS

- unixtime

  Return a unix time (seconds since the epoch) for a random time between the epoch and now.

- date

  Return a random date as a string, using a random date format (see date\_format).

- time

  Return a random time as a string, using a random time format (see time\_format).

- rfc822

  Return an RFC 822 formatted random date.  This method may not work on systems using a non-GNU strftime implementation (kindly let me know if that is the case.)

- ampm

  Returns am or pm randomly (in the current locale) using one of the formats specified in ampm\_format.

- time\_format

  Return a random time format.

- date\_format

  Return a random date format.

- ampm\_format

  Return a random am/pm format.

- datetime\_format

  Return a random date and time format.

- month

  Return a random month name, unabbreviated, in the current locale.

- month\_abbr

  Return a random month name, abbreviated, in the current locale.

- weekday

  Return a random weekday name, unabbreviated, in the current locale.

- weekday\_abbr

  Return a random weekday name, abbreviated, in the current locale.

- sqldate

  Return a random date in the ISO8601 format commonly used by SQL servers (YYYY-MM-DD).

- datetime\_locale

  Return a datetime string in the preferred date representation for the current locale, for a random date.

- date\_locale

  Return a date string in the preferred date representation for the current locale, for a random date.

- time\_locale

  Return a time string in the preferred date representation for the current locale, for a random date.

- century

  Return a random century number.

- dayofmonth

  Return a random day of the month.

## UTILITY METHODS

- Data::Faker::DateTime::timestr($format);

  Given a strftime format specifier, this method passes it through to POSIX::strftime along with a random date to display in that format.

  Perl passes this through to the strftime function of your system library, so it is possible that some of the formatting tokens used here will not work on your system.

## NOTES AND CAVEATS

- Be careful building timestamps from pieces

  Be very careful about building date/time representations in formats that are not already listed here.  For example if you wanted to get a date that consists of just the month and day, you should NOT do this:

  ```
    my $faker = Data::Faker->new();
    print join(' ',$faker->month,$faker->dayofmonth)."\n";
  ```

  This is bad because you might end up with 'February 31' for example.  Instead you should use the timestr utility function to provide you a formatted time for a valid date, or better still, write a plugin function that does it:

  ```
    my $faker = Data::Faker->new();
    print $faker->my_short_date()."\n";
    package Data::Faker::MyExtras;
    use base qw(Data::Faker);
    use Data::Faker::DateTime;
    __PACKAGE__->register_plugin(
      my_short_date => sub { Data::Faker::DateTime::timestr('%M %e') },
    );
  ```

- POSIX::strftime

  See the documentation above regarding the timestr utility method for some caveats related to strftime and your system library.

## SEE ALSO

Data::Faker

## AUTHOR

Jason Kohles, \<email@jasonkohles.com\>

## COPYRIGHT AND LICENSE

Copyright 2004-2005 by Jason Kohles

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