HumHub Documentation (unofficial)

DateTimeExtension

FakerPHP extension for Date-related randomization.

Functions accepting a date string use the strtotime() function internally.

Tags
experimental
since
1.20.0

Table of Contents

Methods

amPm()  : string
Get a string containing either "am" or "pm".
century()  : string
Get a random century, formatted as Roman numerals.
date()  : string
Get a date string between January 1, 1970, and `$until`.
dateTime()  : DateTime
Get a DateTime object between January 1, 1970, and `$until` (defaults to "now").
dateTimeAD()  : DateTime
Get a DateTime object for a date between January 1, 0001, and now.
dateTimeBetween()  : DateTime
Get a DateTime object a random date between `$from` and `$until`.
dateTimeInInterval()  : DateTime
Get a DateTime object based on a random date between `$from` and an interval.
dateTimeThisCentury()  : DateTime
Get a date time object somewhere inside the current century.
dateTimeThisDecade()  : DateTime
Get a date time object somewhere inside the current decade.
dateTimeThisMonth()  : DateTime
Get a date time object somewhere inside the current month.
dateTimeThisWeek()  : DateTime
Get a date time object somewhere inside the current week.
dateTimeThisYear()  : DateTime
Get a date time object somewhere inside the current year.
dayOfMonth()  : string
Get a localized random day of the month.
dayOfWeek()  : string
Get a localized random day of the week.
iso8601()  : string
Get a date string according to the ISO-8601 standard.
month()  : string
Get a random month (numbered).
monthName()  : string
Get a random month.
time()  : string
Get a time string (24h format by default).
timezone()  : string
Get a random timezone, uses `\DateTimeZone::listIdentifiers()` internally.
unixTime()  : int
Get a UNIX (POSIX-compatible) timestamp between January 1, 1970, and `$until`.
year()  : string
Get a random year between 1970 and `$until`.

Methods

amPm()

Get a string containing either "am" or "pm".

public amPm([DateTime|int|string $until = 'now' ]) : string
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Tags
example

'am'

Return values
string

century()

Get a random century, formatted as Roman numerals.

public century() : string
Tags
example

'XVII'

Return values
string

date()

Get a date string between January 1, 1970, and `$until`.

public date([string $format = 'Y-m-d' ][, DateTime|int|string $until = 'now' ]) : string
Parameters
$format : string = 'Y-m-d'

DateTime format

$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Tags
see
https://www.php.net/manual/en/datetime.format.php
Return values
string

dateTime()

Get a DateTime object between January 1, 1970, and `$until` (defaults to "now").

public dateTime([DateTime|int|string $until = 'now' ][, string|null $timezone = null ]) : DateTime
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

$timezone : string|null = null

zone timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
see
DateTimeZone
see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
example

DateTime('2005-08-16 20:39:21')

Return values
DateTime

dateTimeAD()

Get a DateTime object for a date between January 1, 0001, and now.

public dateTimeAD([DateTime|int|string $until = 'now' ][, string|null $timezone = null ]) : DateTime
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

$timezone : string|null = null

zone timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
example

DateTime('1265-03-22 21:15:52')

see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
Return values
DateTime

dateTimeBetween()

Get a DateTime object a random date between `$from` and `$until`.

public dateTimeBetween([DateTime|string $from = '-30 years' ][, DateTime|int|string $until = 'now' ][, string|null $timezone = null ]) : DateTime

Accepts date strings that can be recognized by strtotime().

Parameters
$from : DateTime|string = '-30 years'

defaults to 30 years ago

$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

$timezone : string|null = null

zone timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
see
DateTimeZone
see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
Return values
DateTime

dateTimeInInterval()

Get a DateTime object based on a random date between `$from` and an interval.

public dateTimeInInterval([DateTime|int|string $from = '-30 years' ][, string $interval = '+5 days' ][, string|null $timezone = null ]) : DateTime

Accepts date string that can be recognized by strtotime().

Parameters
$from : DateTime|int|string = '-30 years'

defaults to 30 years ago

$interval : string = '+5 days'

defaults to 5 days after

$timezone : string|null = null

zone timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
see
DateTimeZone
see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
Return values
DateTime

dateTimeThisCentury()

Get a date time object somewhere inside the current century.

public dateTimeThisCentury([DateTime|int|string $until = 'now' ][, string|null $timezone = null ]) : DateTime
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

$timezone : string|null = null

timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
see
DateTimeZone
see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
Return values
DateTime

dateTimeThisDecade()

Get a date time object somewhere inside the current decade.

public dateTimeThisDecade([DateTime|int|string $until = 'now' ][, string|null $timezone = null ]) : DateTime
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

$timezone : string|null = null

timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
see
DateTimeZone
see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
Return values
DateTime

dateTimeThisMonth()

Get a date time object somewhere inside the current month.

public dateTimeThisMonth([DateTime|int|string $until = 'now' ][, string|null $timezone = null ]) : DateTime
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

$timezone : string|null = null

timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
see
DateTimeZone
see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
Return values
DateTime

dateTimeThisWeek()

Get a date time object somewhere inside the current week.

public dateTimeThisWeek([DateTime|int|string $until = 'now' ][, string|null $timezone = null ]) : DateTime
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

$timezone : string|null = null

zone timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
see
DateTimeZone
see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
Return values
DateTime

dateTimeThisYear()

Get a date time object somewhere inside the current year.

public dateTimeThisYear([DateTime|int|string $until = 'now' ][, string|null $timezone = null ]) : DateTime
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

$timezone : string|null = null

timezone for generated date, fallback to DateTime::$defaultTimezone and date_default_timezone_get().

Tags
see
DateTimeZone
see
http://php.net/manual/en/timezones.php
see
http://php.net/manual/en/function.date-default-timezone-get.php
Return values
DateTime

dayOfMonth()

Get a localized random day of the month.

public dayOfMonth([DateTime|int|string $until = 'now' ]) : string
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Tags
example

'16'

Return values
string

dayOfWeek()

Get a localized random day of the week.

public dayOfWeek([DateTime|int|string $until = 'now' ]) : string

Uses internal DateTime formatting, hence PHP's internal locale will be used (change using setlocale()).

Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Tags
example

'Tuesday'

see
setlocale
see
https://www.php.net/manual/en/function.setlocale.php

Set a different output language

Return values
string

iso8601()

Get a date string according to the ISO-8601 standard.

public iso8601([DateTime|int|string $until = 'now' ]) : string
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Return values
string

month()

Get a random month (numbered).

public month([DateTime|int|string $until = 'now' ]) : string
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Tags
example

'7'

Return values
string

time()

Get a time string (24h format by default).

public time([string $format = 'H:i:s' ][, DateTime|int|string $until = 'now' ]) : string
Parameters
$format : string = 'H:i:s'

DateTime format

$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Tags
see
https://www.php.net/manual/en/datetime.format.php
Return values
string

timezone()

Get a random timezone, uses `\DateTimeZone::listIdentifiers()` internally.

public timezone([string|null $countryCode = null ]) : string
Parameters
$countryCode : string|null = null

two-letter ISO 3166-1 compatible country code

Tags
example

'Europe/Rome'

Return values
string

unixTime()

Get a UNIX (POSIX-compatible) timestamp between January 1, 1970, and `$until`.

public unixTime([DateTime|int|string $until = 'now' ]) : int
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Return values
int

year()

Get a random year between 1970 and `$until`.

public year([DateTime|int|string $until = 'now' ]) : string
Parameters
$until : DateTime|int|string = 'now'

maximum timestamp, defaults to "now"

Tags
example

'1987'

Return values
string

        
On this page

Search results