Convert Figma logo to code with AI

flatpickr logoflatpickr

lightweight, powerful javascript datetimepicker with no dependencies

16,362
1,473
16,362
841

Top Related Projects

8,065

A refreshing JavaScript Datepicker — lightweight, no dependencies, modular CSS

A powerful Date/time picker widget.

JavaScript Date Range, Date and Time Picker Component

jQuery Plugin Date and Time Picker

Duet Date Picker is an open source version of Duet Design System’s accessible date picker. Try live example at https://duetds.github.io/date-picker/

Quick Overview

Flatpickr is a lightweight and powerful datetime picker library for JavaScript. It provides a customizable and feature-rich solution for selecting dates and times in web applications, with support for various date formats, time zones, and localization.

Pros

  • Lightweight and performant, with no dependencies
  • Highly customizable with extensive options and theming capabilities
  • Supports both date and time picking, as well as range selection
  • Easy to integrate with various frameworks and libraries

Cons

  • Learning curve for advanced customizations
  • Limited built-in accessibility features
  • Some users report occasional issues with mobile device compatibility
  • Documentation could be more comprehensive for complex use cases

Code Examples

  1. Basic date picker initialization:
flatpickr("#myDatePicker", {
  dateFormat: "Y-m-d",
  minDate: "today"
});
  1. Date range picker with time:
flatpickr("#dateRange", {
  mode: "range",
  enableTime: true,
  dateFormat: "Y-m-d H:i",
  minDate: "today"
});
  1. Custom formatting and localization:
flatpickr("#localizedPicker", {
  dateFormat: "d.m.Y",
  locale: "de",
  weekNumbers: true,
  altInput: true,
  altFormat: "F j, Y"
});

Getting Started

To use Flatpickr in your project, follow these steps:

  1. Include Flatpickr in your HTML:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
  1. Create an input element in your HTML:
<input type="text" id="datepicker" placeholder="Select Date...">
  1. Initialize Flatpickr in your JavaScript:
flatpickr("#datepicker", {
  // Options go here
});

That's it! You now have a basic Flatpickr date picker set up in your project. Customize it further by exploring the various options available in the documentation.

Competitor Comparisons

8,065

A refreshing JavaScript Datepicker — lightweight, no dependencies, modular CSS

Pros of Pikaday

  • Lightweight and minimalistic, with a smaller file size
  • No dependencies, making it easier to integrate into projects
  • Simple API and straightforward configuration options

Cons of Pikaday

  • Less feature-rich compared to Flatpickr
  • Limited built-in themes and styling options
  • Less frequent updates and maintenance

Code Comparison

Pikaday:

var picker = new Pikaday({
    field: document.getElementById('datepicker'),
    format: 'D MMM YYYY',
    onSelect: function(date) {
        console.log(date);
    }
});

Flatpickr:

flatpickr("#datepicker", {
    dateFormat: "d M Y",
    onChange: function(selectedDates, dateStr, instance) {
        console.log(selectedDates[0]);
    }
});

Both libraries offer similar basic functionality for date picking, but Flatpickr provides more advanced features and customization options out of the box. Pikaday's simplicity may be preferred for projects requiring a lightweight solution, while Flatpickr's extensive feature set and active development make it suitable for more complex applications.

A powerful Date/time picker widget.

Pros of Tempus Dominus

  • More comprehensive date and time selection options, including seconds and milliseconds
  • Better support for localization and internationalization
  • Extensive event system for custom behaviors and integrations

Cons of Tempus Dominus

  • Larger file size and potentially heavier performance impact
  • Steeper learning curve due to more complex API and configuration options
  • Less frequent updates and maintenance compared to Flatpickr

Code Comparison

Flatpickr initialization:

flatpickr("#myDatePicker", {
  enableTime: true,
  dateFormat: "Y-m-d H:i",
});

Tempus Dominus initialization:

new tempusDominus.TempusDominus(document.getElementById('myDatePicker'), {
  display: {
    components: {
      seconds: true,
      useTwentyfourHour: true
    },
    format: 'yyyy-MM-dd HH:mm:ss'
  }
});

Both libraries offer powerful date and time picking functionality, but Tempus Dominus provides more advanced features at the cost of complexity. Flatpickr is lighter and easier to use, making it suitable for simpler use cases, while Tempus Dominus excels in scenarios requiring more detailed control and customization.

JavaScript Date Range, Date and Time Picker Component

Pros of Daterangepicker

  • Built-in support for selecting date ranges, which is its primary focus
  • Offers pre-defined date ranges (e.g., "Last 7 Days", "This Month")
  • Integrates well with Bootstrap for consistent styling

Cons of Daterangepicker

  • Larger file size and more dependencies (jQuery and Moment.js required)
  • Less customizable in terms of appearance and functionality
  • Not as actively maintained as Flatpickr

Code Comparison

Daterangepicker:

$('input[name="daterange"]').daterangepicker({
    startDate: moment().subtract(7, 'days'),
    endDate: moment(),
    locale: {
        format: 'YYYY-MM-DD'
    }
});

Flatpickr:

flatpickr("#date-range", {
    mode: "range",
    dateFormat: "Y-m-d",
    defaultDate: [new Date().fp_incr(-7), new Date()]
});

Both libraries offer date range selection, but Flatpickr provides a more lightweight and flexible solution. Daterangepicker excels in pre-defined ranges and Bootstrap integration, while Flatpickr offers broader browser support and more customization options. The choice between them depends on specific project requirements and preferences.

jQuery Plugin Date and Time Picker

Pros of datetimepicker

  • More extensive customization options for appearance and behavior
  • Supports a wider range of date and time formats
  • Includes additional features like inline mode and custom cell rendering

Cons of datetimepicker

  • Larger file size and potentially heavier performance impact
  • Less frequent updates and maintenance compared to flatpickr
  • More complex configuration and setup process

Code Comparison

datetimepicker:

$('#datetimepicker').datetimepicker({
  format: 'Y-m-d H:i',
  inline: true,
  lang: 'en'
});

flatpickr:

flatpickr("#flatpickr", {
  enableTime: true,
  dateFormat: "Y-m-d H:i",
  inline: true
});

Summary

datetimepicker offers more extensive customization and features, making it suitable for complex date and time selection requirements. However, it comes at the cost of a larger file size and potentially more complex setup. flatpickr, on the other hand, provides a lighter-weight solution with a simpler API, making it easier to implement for basic date and time picking needs. The choice between the two depends on the specific requirements of your project, balancing between feature richness and simplicity.

Duet Date Picker is an open source version of Duet Design System’s accessible date picker. Try live example at https://duetds.github.io/date-picker/

Pros of date-picker

  • Built with web components, offering better encapsulation and reusability
  • Designed with accessibility in mind, following WCAG 2.1 guidelines
  • Lightweight and framework-agnostic, easily integrable into various projects

Cons of date-picker

  • Less customizable compared to flatpickr's extensive options
  • Smaller community and fewer third-party extensions
  • Limited to date picking functionality, while flatpickr offers more features

Code Comparison

date-picker:

<duet-date-picker identifier="date" name="date"></duet-date-picker>

flatpickr:

<input type="text" class="flatpickr" data-date-format="Y-m-d" />
<script>
  flatpickr(".flatpickr", {});
</script>

Summary

date-picker focuses on simplicity, accessibility, and framework independence using web components. It's ideal for projects prioritizing these aspects. flatpickr offers more customization options and features, making it suitable for complex date-time picking requirements. The choice between them depends on specific project needs and preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

flatpickr - javascript datetime picker

Actions Status

Coverage npm version CDNJS License

blue green confetti red default dark

Motivation

Almost every large SPA or project involves date and time input. Browser's native implementations of those are inconsistent and limited in functionality. Most other libraries require you to pull in heavy dependencies like jQuery, Bootstrap, and moment.js. I wanted something that was good-looking out of the box, dependency-free, powerful, and extensible.

Feature overview:

  • Dependency-free (no bloated bundles)
  • Simple, polished UX
  • Date + time input
  • Range selections
  • Ability to select multiple dates
  • Can be used as just a time picker
  • Display dates in a human-friendly format
  • Easily disable specific dates, date ranges, or any date using arbitrary logic
  • Week numbers
  • 51 locales
  • 8 colorful themes (incl. dark and material)
  • Numerous plugins
  • Libraries available for React, Angular, Vue, Ember, and more

flatpickr provides more functionality at a fraction of the size of other libraries.

Compatibility

IE9 and up, Edge, iOS Safari 6+, Chrome 8+, Firefox 6+

Install & Use

Demos and documentation: https://flatpickr.js.org

See also:

Supporting flatpickr

flatpickr will never change its license, pester users for donations, or engage in other user-hostile behavior.

Nevertheless, if you enjoyed working with this library or if its made your life easier, you can buy me a cup of coffee :)

Buy Me a Coffee at ko-fi.com

NPM DownloadsLast 30 Days