Managing Date and Time Formats in PHP Applications
Technical Guide for Developers

The Bootstrap admin dashboard has to juggle with different date and time formats depending on the situation. Here's how it works.


The different Date and Time formats

List of the date, datetime and time formats used in PHP CRUD Generator

Pages Usage Language Format
READ lists Human readable date translated according to the user language PHP with intl extension enabled ICU *
READ lists Human readable date NOT translated PHP without intl extension enabled PHP date format **
CREATE / UPDATE forms Datepicker plugins Javascript Pickadate plugin formats ***
PHP Objects Database date, time and datetime fields PHP/MySQL Y-m-d H:i:s

*ICU - https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details

**PHP date formats list: https://www.php.net/manual/en/function.date.php

***Pickadate date formats list: https://amsul.ca/pickadate.js/date/


Management of PHP/JavaScript date and time formats in the admin dashboard

The Generator and Admin panel date & time formats

  1. When you set a date / time format in a generator READ list, your choice is stored in internal file (generator/database/phpcg/[your_table].json).

    The format stored is the Javascript format

    The admin form's date & time pickers will use this format, + an hidden field with a "_submit" suffix to send the values in MySQL date / time format.

  2. The TWIG READ list template will later need to convert the date / time from the MySQL value to the human readable format.
    For this purpose, the Javascript format is converted by the generator to PHP ICU by generator/class/generator/TemplatesUtilities.php. The generated PHP ICU format will be passed as argument in the TWIG template to convert the MySQL date / time to the human readable format.

    The function is pickerdateToPhpdate($pickerdate)

  3. The item class builds the object value using the PHP/MySQL format (no format conversion)

  4. the READ list TWIG template calls the formatDate($date, $format) function in vendor/twig/twig/lib/Twig/Extension/CrudTwigExtension.php

    The given $date is in PHP/MySQL format and can be a date, a time or a datetime.

    The given $format is the ICU format.

    • if PHP intl extension is enabled it'll show the date translated according to your languages settings with IntlDateFormatter::formatObject() using Locale::getDefault()
    • if PHP intl extension is not enabled it converts the ICU date / time to the classic PHP date format

Random datetime formats examples

The datetimes below are generated from a random format using the same logic as the CRUD Generator.

$pickerdate
yyyy mm dddd h i A
$icu_format
yyyy MM eeee h m a
$icu_date
2025 02 Monday 7 15 pm
$php_format
Y m l g i a
$php_date
2025 02 Monday 7 15 pm

$pickerdate
yyyy mmmm d H i a
$icu_format
yyyy MMMM d H m a
$icu_date
2025 February 24 19 15 pm
$php_format
Y F j G i a
$php_date
2025 February 24 19 15 pm

$pickerdate
yyyy mm dddd HH i A
$icu_format
yyyy MM eeee HH m a
$icu_date
2025 02 Monday 19 15 pm
$php_format
Y m l H i a
$php_date
2025 02 Monday 19 15 pm

$pickerdate
yy mm ddd H i A
$icu_format
yy MM eee H m a
$icu_date
25 02 Mon 19 15 pm
$php_format
y m D G i a
$php_date
25 02 Mon 19 15 pm

$pickerdate
yyyy m dd h i A
$icu_format
yyyy M dd h m a
$icu_date
2025 2 24 7 15 pm
$php_format
Y n d g i a
$php_date
2025 2 24 7 15 pm

$pickerdate
yy mm d HH i a
$icu_format
yy MM d HH m a
$icu_date
25 02 24 19 15 pm
$php_format
y m j H i a
$php_date
25 02 24 19 15 pm

$pickerdate
yyyy m dddd hh i a
$icu_format
yyyy M eeee hh m a
$icu_date
2025 2 Monday 07 15 pm
$php_format
Y n l h i a
$php_date
2025 2 Monday 07 15 pm

$pickerdate
yy mmmm dd hh i A
$icu_format
yy MMMM dd hh m a
$icu_date
25 February 24 07 15 pm
$php_format
y F d h i a
$php_date
25 February 24 07 15 pm

$pickerdate
yyyy mm ddd hh i a
$icu_format
yyyy MM eee hh m a
$icu_date
2025 02 Mon 07 15 pm
$php_format
Y m D h i a
$php_date
2025 02 Mon 07 15 pm

$pickerdate
yy mm ddd hh i A
$icu_format
yy MM eee hh m a
$icu_date
25 02 Mon 07 15 pm
$php_format
y m D h i a
$php_date
25 02 Mon 07 15 pm

PHP CRUD tutorial main page