How to use the date time widget in concrete5 5.7

This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
Apr 27, 2015

The date time widget has three methods.
date()
datetime()
translate()

Core::make('helper/form/date_time')

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 )

http://documentation.concrete5.org/api/class-Concrete.Core.Form.Service.Widget.DateTime.html

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');
    parent::save($args);
}

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

http://www.concrete5.org/documentation/how-tos/creating-and-working-with-db-xml-files/

Recent Tutorials
How to Automate the Copyright Year
Dec 27, 2024

Learn how to keep your website's copyright year updated automatically in Concrete CMS.

How to change the path of a group of pages
Dec 23, 2024
By myq.

Change the canonical path without breaking things

Bi-directional Express associations
Dec 18, 2024
By myq.

Set up associations between Express entries in both directions

Display Express Data Across Multiple Sites
Dec 17, 2024
By myq.

A guide to configuring Express entities and the Express Entry List block to ensure proper data display across multiple sites.

Customize locale icons
Oct 29, 2024
By myq.

How to customize locale (language region) flags

Concrete CMS Caching Guide
Oct 16, 2024

An overview of types of caching in Concrete and considerations when using them.

Improvements?

Let us know by posting here.