📙
QuickAdminPanel
  • QuickAdminPanel Docs
  • Quick Start: Creating Panel
    • Creating a Simple CRUD
    • Radio/Checkbox/Select Fields
    • Relationships fields: belongsTo/belongsToMany
    • File/Photo Upload Fields
    • Date/Time Picker Fields
    • Multi-language Projects
    • API Generator
    • Roles and Permissions
    • How to Change Design Template/Theme
  • Using the Generated Code
    • Download Code and Install on Your Web-Server
    • Push Code to Your Github
    • Edit Code and Merge Changes
    • What Files are Inside the CRUD
  • Modules
    • Modules Overview
    • AJAX Datatables
    • System Calendar
    • Audit Changes Logs
    • Dashboard and Reports
    • Multi-Tenancy
    • CSV Import
    • Global Search
    • User Registration
    • Internal Messages
    • Change Notifications
    • Tasks + Calendar
    • Courses LMS
    • CRUD Templates Modules
  • Customizing the Code
    • Datatables Customizations
    • Upgrade Laravel version
    • Dependent Dropdowns: Parent-Child
    • Add Front User Without Admin Permissions
    • How to Add Mass Actions to Datatable
  • Vue.js + Laravel API Version
    • QuickAdminPanel: Vue.js+Laravel Version
    • What Files are Inside Vue.js+Laravel CRUD?
    • Installing Downloaded Vue.js+Laravel Panel
  • Livewire + Tailwind Version
    • QuickAdminPanel: Livewire+Tailwind Version
    • What Files are Inside Livewire+Tailwind CRUD?
    • Installing Downloaded Livewire+Tailwind Panel
Powered by GitBook
On this page
  • How it Looks
  • How It Works
  • How to Configure/Customize
  • Example 1. 12-hour Clock instead of a 24-hour Clock
  • Example 2. Don't Display Seconds
  1. Quick Start: Creating Panel

Date/Time Picker Fields

PreviousFile/Photo Upload FieldsNextMulti-language Projects

Last updated 4 years ago

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

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />

...

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>

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.

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>

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

  moment.updateLocale('en', {
    week: {dow: 1} // Monday is the first day of the week
  })

  $('.date').datetimepicker({
    format: 'MM/DD/YYYY',
    locale: 'en',
    icons: {
      up: 'fas fa-chevron-up',
      down: 'fas fa-chevron-down',
      previous: 'fas fa-chevron-left',
      next: 'fas fa-chevron-right'
    }
  })

  $('.datetime').datetimepicker({
    format: 'MM/DD/YYYY HH:mm:ss',
    locale: 'en',
    sideBySide: true,
    icons: {
      up: 'fas fa-chevron-up',
      down: 'fas fa-chevron-down',
      previous: 'fas fa-chevron-left',
      next: 'fas fa-chevron-right'
    }
  })

  $('.timepicker').datetimepicker({
    format: 'HH:mm:ss',
    icons: {
      up: 'fas fa-chevron-up',
      down: 'fas fa-chevron-down',
      previous: 'fas fa-chevron-left',
      next: 'fas fa-chevron-right'
    }
  })

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:

return [
    'date_format' => 'm/d/Y',
    'time_format' => 'H:i:s',
    
    // ... other parameters
];

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

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:

return [
    'date_format' => 'm/d/Y',
    'time_format' => 'h:i A',   // changed from 'H:i:s'

public/js/main.js:

$('.datetime').datetimepicker({
    format: 'MM/DD/YYYY hh:mm A',   // changed from 'MM/DD/YYYY HH:mm:ss'

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:

return [
    'date_format' => 'm/d/Y',
    'time_format' => 'H:i',   // changed from 'H:i:s'

public/js/main.js:

$('.datetime').datetimepicker({
    format: 'MM/DD/YYYY HH:mm',   // changed from 'MM/DD/YYYY HH:mm:ss'

To make those pickers work, we're loading a directly from CDN:

We also load the from CDN, which helps with time manipulation in JavaScript:

Keep in mind that JavaScript formats are powered by , and Laravel formats are powered by the .

Bootstrap Date/Time Picker library
Moment.js library
Moment.js
PHP date() function