The date time widget has three methods.


date( string $field, string $value = null, boolean $calendarAutoStart = true )

datetime( string $prefix, string $value = null, boolean $includeActivation = false, boolean $calendarAutoStart = true )

translate( string $field, array $arr = null )

in form.php:

Date Only Picker:

Core::make('helper/form/date_time')->date('date_only', $date_only);

Using the date time widget to get a date picker using the date() method.

date('field', $value)

This creates the jQuery UI date picker. The date value saved is in "Y-m-d" format.

Date and Time Picker

Core::make('helper/form/date_time')->datetime('date_and_time', $date_and_time);

Using the date time widget to get a date and time picker using the datetime() method.

datetime('field', $value)

In addition to the jQuery UI date picker, there will be a select drop down for hours, minutes, and AM/PM. The date/time value saved is in "Y-m-d H:i:s" MySQL timestamp format.

When using the datetime() method, it creates multiple fields that must be combined using the translate() method. The save() method must be extended in the block controller to use translate().

in controller.php

public function save($args)
    $args['date_and_time'] = Core::make('helper/form/date_time')->translate('date_and_time');

The save() method is extended to use the translate() method. The $args paramenter is the POST superglobal array. The date/time picker returns values from multiple fields - date, hour, minutes, and AM/PM. The different date/time fields need to be combined (translated) into a timestamp (combined into one value) to be saved. Translate() combines the different date/time fields from the POST superglobal array and translates (combines) them into a timestamp.

in db.xml

The field type for date and date/time is "T".
T: Datetime or Timestamp accurate to the second

Loading Conversation