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
Upgrade Concrete versions 9.3.1 and 9.3.2
Sep 10, 2024
By myq.

How to get past a bug in versions 9.3.1 and 9.3.2 that prevents upgrading the Concrete core through the Dashboard

How to use Composer with Marketplace extensions
Aug 22, 2024

Composer can be used to manage third-party extensions from the marketplace

Controlling Google Tag Manager Tags Based on Concrete CMS Edit Toolbar Visibility
Aug 13, 2024

This document provides a step-by-step guide on how to control the firing of Google Tag Manager (GTM) tags based on the visibility of the Concrete CMS edit toolbar. It explains how to create a custom JavaScript variable in GTM to detect whether the edit toolbar is present on a page and how to set up a trigger that ensures GTM tags only fire when the toolbar is not visible. This setup is particularly useful for developers and marketers who want to ensure that tracking and analytics tags are not activated during content editing sessions, thereby preserving the accuracy of data collected.

Upgrading Concrete from 8.5 to 9.x
Jun 21, 2024
By myq.

How to avoid problems upgrading from 8.5 to 9.x

How to change the default date format
May 30, 2024
By myq.

Change the format of the default date

WebOps Tutorial on Running and Upgrading a Concrete CMS Website
May 2, 2024
By myq.

Describes how to deploy, manage, and upgrade a Concrete CMS website

Improvements?

Let us know by posting here.