Date/Time Picker Fields

How it Looks

We have three field types related to date and/or time:

To make the input more convenient, we use a jQuery library called Datetimepicker, to power all of them. Here's how it looks visually.

Date Picker:

Date/Time Picker:

Time Picker:

How It Works

To make those pickers work, we're loading a Bootstrap Date/Time Picker libraryarrow-up-right directly from CDN:

Notice: that library is now renamed to "Tempus Dominus" and is in process of creating a new version, but we're using older and stable v4.17.

We also load the Moment.js libraryarrow-up-right from CDN, which helps with time manipulation in JavaScript:

Then, in the file public/js/main.js we have this jQuery code to enable pickers:

So, in Blade files, every picker input field has its class, like <input class="date" />, or <input class="datetime" />, or <input class="timepicker" />.

How to Configure/Customize

The most typical customization is changing the date/time formats. I will show you two examples.

First, you can configure your date format in the panel settings:

After downloading the code, you can also make the changes. Besides the date formats you can see in the previous code sample (like, "format: 'MM/DD/YYYY HH:mm:ss'"), we also have the configuration on the back-end of Laravel, to convert the dates to/from the database.

So, here's config/panel.php:

So, if you want to change the formats, you need to change them both in JavaScript, and in Laravel.

Keep in mind that JavaScript formats are powered by Moment.jsarrow-up-right, and Laravel formats are powered by the PHP date() functionarrow-up-right.

Example 1. 12-hour Clock instead of a 24-hour Clock

To use hours like "3pm" instead of "15", you need to make these changes:

config/panel.php:

public/js/main.js:

Example 2. Don't Display Seconds

If you want to skip seconds in datetime/time picker, here are the changes to make:

config/panel.php:

public/js/main.js:

Last updated