General

  eZ Systems Website
  Editor documentation


  Developer documentation

  Back to the top

The documentation is moving!

We're moving our developer docs to Github and a new site.
The migration is still in progress, so please contact us in #documentation-contrib on eZ Community Slack if you have any questions or feedback.

This space will not be updated from now on except for critical fixes.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: link fix

This Field Type represents a full date including time information.

NameInternal nameExpected input type
DateAndTimeezdatetimemixed

Description

This Field Type makes possible to store and retrieve a full date including time information.

PHP API Field Type 

Input expectations

If input value is of type string or integer, it will be passed directly to the PHP's built-in \DateTime class constructor, therefore the same input format expectations apply.

It is also possible to directly pass an instance of \DateTime.

TypeExample
string"2012-08-28 12:20 Europe/Berlin"
integer
1346149200
\DateTime
new \DateTime()

Value object

Properties

The Value class of this field type contains the following properties:

PropertyTypeDescription
$value\DateTimeThe date and time value as an instance of \DateTime.
Constructor

The constructor for this value object will initialize a new Value object with the value provided. It accepts an instance of PHP's built-in \DateTime class.

String representation

String representation of the date value will generate the date string in the format "D Y-d-m H:i:s" as accepted by PHP's built-in date() function.

Example:

Wed 2013-22-05 12:19:18


Hash format

Hash value of this Field Type is an array with two keys:

KeyTypeDescriptionExample

timestamp

integerTime information as a timestamp.

1400856992

rfc850

string

Time information as a string in RFC 850 date format.

As input, this will have higher precedence over the timestamp value.

"Friday, 23-May-14 14:56:14 GMT+0000"
Code Block
languagephp
linenumberstrue
$hash = array(
	"timestamp" => 1400856992,
	"rfc850" => "Friday, 23-May-14 14:56:14 GMT+0000"
);

Validation

This Field Type does not perform any special validation of the input value.

Settings

The field definition of this Field Type can be configured with several options:

NameTypeDefault valueDescription
useSecondsbooleanfalseUsed to control displaying of seconds in the output.
defaultType
mixed
Type::DEFAULT_EMPTY

One of the DEFAULT_* constants, used by the administration interface for setting the default field value.

See below for more details.

dateInterval
null|\DateInterval
null

This setting complements defaultType setting and can be used only when latter is set to Type::DEFAULT_CURRENT_DATE_ADJUSTED.

In that case the default input value when using administration interface will be adjusted by the given \DateInterval.

Following defaultType default value options are available as constants in the eZ\Publish\Core\FieldType\DateAndTime\Type class:

ConstantDescription
DEFAULT_EMPTY
Default value will be empty.
DEFAULT_CURRENT_DATE
Default value will use current date.
DEFAULT_CURRENT_DATE_ADJUSTED
Default value will use current date, adjusted by the interval defined in dateInterval setting.
Code Block
languagephp
titleDateAndTime FieldType example settings
linenumberstrue
use eZ\Publish\Core\FieldType\DateAndTime\Type;

$settings = array(
	"useSeconds" => false,
	"defaultType" => Type::DEFAULT_EMPTY,
	"dateInterval" => null
);

Template rendering

The template called by the ez_render_field() Twig function while rendering a Date field has access to the following parameters:

ParameterTypeDefaultDescription
localestring Internal parameter set by the system based on current request locale or if not set calculated based on the language of the field.

Example:

Code Block
{{ ez_render_field(content, 'datetime') }}