Displays a calendar field to pick dates and times.

type

(string)  Must be equals to date.

label

(string)  The label to display next to the field.

help

(string)  An optional text to describe the purpose of the field.

required

(bool)  Whether the field is mandatory or optional.

default

(string)  An optional pre-selected date.

value

(string)  The last saved date.

id

(string)  An optional field ID.

class

(string)  An optional field class suffix.

hidden

(bool)  True to avoid displaying the label of the field.

attrs

(array)  An associative array containing additional calendar options.

  • onChange - the javascript callback to invoke after picking a date;
  • showTime - whether the field should allow the selection of the time too (false by default).

The format of the date is always equals to the one specified from the global configuration of VikAppointments. The time is rather always display using the 24H format. The value of the date can be specified in 3 different ways.

Pre-Formatted Date

It is possible to manually pre-format the date according to the format accepted by the system.

$value = JHtml::_('date', '2022-03-01 10:00', VAPFactory::getConfig()->get('dateformat'));

Date Object

Construct a date object adjusted to the local timezone of the currently logged-in user.

$valur = JFactory::getDate('2022-03-01 10:00', JFactory::getUser()->getTimezone());

Timestamp

This technique is discouraged because the system will reformat the specified timestamp according to the server timezone.

$value = mktime(10, 0, 0, 3, 1, 2022);
[
    'reminder' => [
        'type' => 'date',
        'label' => 'Reminder',
        'value' => JFactory::getDate('2022-03-10 10:00', JFactory::getUser()->getTimezone()),
        'attrs' => [
            'showTime' => true,
         ],
    ]
]

Changelog

Version Description
1.7.3 Introduced.
Last Update: 2022-03-09 14:37
Helpful?