PHPackages                             rhubarbphp/pikaday - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. rhubarbphp/pikaday

ActiveLibrary

rhubarbphp/pikaday
==================

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

1.6.1(8y ago)011.6k1BSDJavaScript

Since Jan 22Pushed 8y ago4 watchersCompare

[ Source](https://github.com/RhubarbPHP/Pikaday)[ Packagist](https://packagist.org/packages/rhubarbphp/pikaday)[ Docs](http://dbushell.github.io/Pikaday/)[ RSS](/packages/rhubarbphp-pikaday/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (1)

Pikaday
=======

[](#pikaday)

[![NPM version](https://camo.githubusercontent.com/bf121e5d554a4927b74d656bcb15646625686033f3bc8cc0df8a7e20f5a508ee/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f70696b616461792e7376673f7374796c653d666c61742d737175617265)](https://npmjs.org/package/pikaday)[![License](https://camo.githubusercontent.com/8b8951043d9560478bc5f05644d92c7c8d4243a46b9d35ac6f003b0293c749a2/68747470733a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Downloads](https://camo.githubusercontent.com/f8dcfdb631d5ef14acdc50904ee585217cd0b631d9d1e1eb611d7ad4a55370ac/687474703a2f2f696d672e736869656c64732e696f2f6e706d2f646d2f70696b616461792e7376673f7374796c653d666c61742d737175617265)](https://npmjs.org/package/pikaday)

### A refreshing JavaScript Datepicker

[](#a-refreshing-javascript-datepicker)

- Lightweight (less than 5kb minified and gzipped)
- No dependencies (but plays well with [Moment.js](http://momentjs.com/ "moment.js"))
- Modular CSS classes for easy styling

[**Try Pikaday Demo →**](http://dbushell.github.com/Pikaday/ "Pikaday")

[![Pikaday Screenshot](https://camo.githubusercontent.com/c72b247fa0dc73367f3749bee9941d50fd4a1a14b86958eee824469cbb076a2d/68747470733a2f2f7261772e6769746875622e636f6d2f6462757368656c6c2f50696b616461792f67682d70616765732f73637265656e73686f742e706e67 "Screenshot")](https://camo.githubusercontent.com/c72b247fa0dc73367f3749bee9941d50fd4a1a14b86958eee824469cbb076a2d/68747470733a2f2f7261772e6769746875622e636f6d2f6462757368656c6c2f50696b616461792f67682d70616765732f73637265656e73686f742e706e67)

**Production ready?** Since version 1.0.0 Pikaday is stable and used in production. If you do however find bugs or have feature requests please submit them to the [GitHub issue tracker](https://github.com/dbushell/Pikaday/issues "Issue tracker"). Also see the [changelog](CHANGELOG.md)

Installation
------------

[](#installation)

```
npm install pikaday

```

Usage
-----

[](#usage)

**Pikaday** can be bound to an input field:

```

```

Add the JavaScript to the end of your document:

```

    var picker = new Pikaday({ field: document.getElementById('datepicker') });

```

If you're using **jQuery** make sure to pass only the first element:

```
var picker = new Pikaday({ field: $('#datepicker')[0] });
```

If the Pikaday instance is not bound to a field you can append the element anywhere:

```
var field = document.getElementById('datepicker');
var picker = new Pikaday({
    onSelect: function(date) {
        field.value = picker.toString();
    }
});
field.parentNode.insertBefore(picker.el, field.nextSibling);
```

### Formatting

[](#formatting)

By default, dates are formatted and parsed using standard JavaScript Date object. If [Moment.js](http://momentjs.com/ "moment.js") is available in scope, it will be used to format and parse input values. You can pass an additional `format` option to the configuration which will be passed to the `moment` constructor. See the [moment.js example](http://dbushell.github.com/Pikaday/examples/moment.html "Pikaday w/ moment.js") for a full version.

```

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

```

For more advanced and flexible formatting you can pass your own `toString` function to the configuration which will be used to format the date object. This function has the following signature:

`toString(date, format = 'YYYY-MM-DD')`

You should return a string from it.

Be careful, though. If the formatted string that you return cannot be correctly parsed by the `Date.parse` method (or by `moment` if it is available), then you must provide your own `parse` function in the config. This function will be passed the formatted string and the format:

`toString(dateString, format = 'YYYY-MM-DD')`

```
var picker = new Pikaday({
    field: document.getElementById('datepicker'),
    format: 'D/M/YYYY',
    toString(date, format) {
        // you should do formatting based on the passed format,
        // but we will just return 'D/M/YYYY' for simplicity
        const day = date.getDate();
        const month = date.getMonth() + 1;
        const year = date.getFullYear();
        return `${day}/${month}/${year}`;
    },
    parse(dateString, format) {
        // dateString is the result of `toString` method
        const parts = dateString.split('/');
        const day = parseInt(parts[0], 10);
        const month = parseInt(parts[1] - 1, 10);
        const year = parseInt(parts[1], 10);
        return new Date(year, month, day);
    }
});
```

### Configuration

[](#configuration)

As the examples demonstrate above Pikaday has many useful options:

- `field` bind the datepicker to a form field
- `trigger` use a different element to trigger opening the datepicker, see [trigger example](http://dbushell.github.com/Pikaday/examples/trigger.html "Pikaday using custom trigger") (default to `field`)
- `bound` automatically show/hide the datepicker on `field` focus (default `true` if `field` is set)
- `ariaLabel` data-attribute on the input field with an aria assistance tekst (only applied when `bound` is set)
- `position` preferred position of the datepicker relative to the form field, e.g.: `top right`, `bottom right` **Note:** automatic adjustment may occur to avoid datepicker from being displayed outside the viewport, see [positions example](http://dbushell.github.com/Pikaday/examples/positions.html "Pikaday using different position options") (default to 'bottom left')
- `reposition` can be set to false to not reposition datepicker within the viewport, forcing it to take the configured `position` (default: true)
- `container` DOM node to render calendar into, see [container example](http://dbushell.github.com/Pikaday/examples/container.html "Pikaday using custom calendar container") (default: undefined)
- `format` the default output format for `.toString()` and `field` value (requires [Moment.js](http://momentjs.com/ "moment.js") for custom formatting)
- `formatStrict` the default flag for moment's strict date parsing (requires [Moment.js](http://momentjs.com/ "moment.js") for custom formatting)
- `toString(date, format)` function which will be used for custom formatting. This function will take precedence over `moment`.
- `parse(dateString, format)` function which will be used for parsing input string and getting a date object from it. This function will take precedence over `moment`.
- `defaultDate` the initial date to view when first opened
- `setDefaultDate` make the `defaultDate` the initial selected value
- `firstDay` first day of the week (0: Sunday, 1: Monday, etc)
- `minDate` the minimum/earliest date that can be selected (this should be a native Date object - e.g. `new Date()` or `moment().toDate()`)
- `maxDate` the maximum/latest date that can be selected (this should be a native Date object - e.g. `new Date()` or `moment().toDate()`)
- `disableWeekends` disallow selection of Saturdays or Sundays
- `disableDayFn` callback function that gets passed a Date object for each day in view. Should return true to disable selection of that day.
- `yearRange` number of years either side (e.g. `10`) or array of upper/lower range (e.g. `[1900,2015]`)
- `showWeekNumber` show the ISO week number at the head of the row (default `false`)
- `pickWholeWeek` select a whole week instead of a day (default `false`)
- `isRTL` reverse the calendar for right-to-left languages
- `i18n` language defaults for month and weekday names (see internationalization below)
- `yearSuffix` additional text to append to the year in the title
- `showMonthAfterYear` render the month after year in the title (default `false`)
- `showDaysInNextAndPreviousMonths` render days of the calendar grid that fall in the next or previous months (default: false)
- `enableSelectionDaysInNextAndPreviousMonths` allows user to select date that is in the next or previous months (default: false)
- `numberOfMonths` number of visible calendars
- `mainCalendar` when `numberOfMonths` is used, this will help you to choose where the main calendar will be (default `left`, can be set to `right`). Only used for the first display or when a selected date is not already visible
- `events` array of dates that you would like to differentiate from regular days (e.g. `['Sat Jun 28 2017', 'Sun Jun 29 2017', 'Tue Jul 01 2017',]`)
- `theme` define a classname that can be used as a hook for styling different themes, see [theme example](http://dbushell.github.com/Pikaday/examples/theme.html "Pikaday using multiple themes") (default `null`)
- `blurFieldOnSelect` defines if the field is blurred when a date is selected (default `true`)
- `onSelect` callback function for when a date is selected
- `onOpen` callback function for when the picker becomes visible
- `onClose` callback function for when the picker is hidden
- `onDraw` callback function for when the picker draws a new month
- `keyboardInput` enable keyboard input support (default `true`)

jQuery Plugin
-------------

[](#jquery-plugin)

The normal version of Pikaday does not require jQuery, however there is a jQuery plugin if that floats your boat (see `plugins/pikaday.jquery.js` in the repository). This version requires jQuery, naturally, and can be used like other plugins: See the [jQuery example](http://dbushell.github.com/Pikaday/examples/jquery.html "Pikaday w/ jQuery") for a full version.

```

// activate datepickers for all elements with a class of `datepicker`
$('.datepicker').pikaday({ firstDay: 1 });

// chain a few methods for the first datepicker, jQuery style!
$('.datepicker').eq(0).pikaday('show').pikaday('gotoYear', 2042);

```

AMD support
-----------

[](#amd-support)

If you use a modular script loader than Pikaday is not bound to the global object and will fit nicely in your build process. You can require Pikaday just like any other module. See the [AMD example](http://dbushell.github.com/Pikaday/examples/amd.html "Pikaday w/ AMD") for a full version.

```
require(['pikaday'], function(Pikaday) {
    var picker = new Pikaday({ field: document.getElementById('datepicker') });
});
```

The same applies for the jQuery plugin mentioned above. See the [jQuery AMD example](http://dbushell.github.com/Pikaday/examples/jquery-amd.html "Pikaday w/ jQuery + AMD") for a full version.

```
require(['jquery', 'pikaday.jquery'], function($) {
    $('#datepicker').pikaday();
});
```

CommonJS module support
-----------------------

[](#commonjs-module-support)

If you use a CommonJS compatible environment you can use the require function to import Pikaday.

```
var pikaday = require('pikaday');
```

When you bundle all your required modules with [Browserify](http://browserify.org/ "browserify") and you don't use [Moment.js](http://momentjs.com/ "moment.js") specify the ignore option:

`browserify main.js -o bundle.js -i moment`

Ruby on Rails
-------------

[](#ruby-on-rails)

If you're using **Ruby on Rails**, make sure to check out the [Pikaday gem](https://rubygems.org/gems/pikaday-gem "RoR gem").

Methods
-------

[](#methods)

You can control the date picker after creation:

```
var picker = new Pikaday({ field: document.getElementById('datepicker') });
```

### Get and set date

[](#get-and-set-date)

`picker.toString('YYYY-MM-DD')`

Returns the selected date in a string format. If [Moment.js](http://momentjs.com/ "moment.js") exists (recommended) then Pikaday can return any format that Moment understands. You can also provide your own `toString` function and do the formatting yourself. Read more in the [formatting](#formatting) section.

If neither `moment` object exists nor `toString` function is provided, JavaScript's default [`.toDateString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString) method will be used.

`picker.getDate()`

Returns a basic JavaScript `Date` object of the selected day, or `null` if no selection.

`picker.setDate('2015-01-01')`

Set the current selection. This will be restricted within the bounds of `minDate` and `maxDate` options if they're specified. You can optionally pass a boolean as the second parameter to prevent triggering of the onSelect callback (true), allowing the date to be set silently.

`picker.getMoment()`

Returns a [Moment.js](http://momentjs.com/ "moment.js") object for the selected date (Moment must be loaded before Pikaday).

`picker.setMoment(moment('14th February 2014', 'DDo MMMM YYYY'))`

Set the current selection with a [Moment.js](http://momentjs.com/ "moment.js") object (see `setDate` for details).

### Change current view

[](#change-current-view)

`picker.gotoDate(new Date(2014, 1))`

Change the current view to see a specific date. This example will jump to February 2014 ([month is a zero-based index](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date "Date")).

`picker.gotoToday()`

Shortcut for `picker.gotoDate(new Date())`

`picker.gotoMonth(2)`

Change the current view by month (0: January, 1: Februrary, etc).

`picker.nextMonth()``picker.prevMonth()`

Go to the next or previous month (this will change year if necessary).

`picker.gotoYear()`

Change the year being viewed.

`picker.setMinDate()`

Update the minimum/earliest date that can be selected.

`picker.setMaxDate()`

Update the maximum/latest date that can be selected.

`picker.setStartRange()`

Update the range start date. For using two Pikaday instances to select a date range.

`picker.setEndRange()`

Update the range end date. For using two Pikaday instances to select a date range.

### Show and hide datepicker

[](#show-and-hide-datepicker)

`picker.isVisible()`

Returns `true` or `false`.

`picker.show()`

Make the picker visible.

`picker.adjustPosition()`

Recalculate and change the position of the picker.

`picker.hide()`

Hide the picker making it invisible.

`picker.destroy()`

Hide the picker and remove all event listeners — no going back!

### Internationalization

[](#internationalization)

The default `i18n` configuration format looks like this:

```
i18n: {
    previousMonth : 'Previous Month',
    nextMonth     : 'Next Month',
    months        : ['January','February','March','April','May','June','July','August','September','October','November','December'],
    weekdays      : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
    weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
}
```

You must provide 12 months and 7 weekdays (with abbreviations). Always specify weekdays in this order with Sunday first. You can change the `firstDay` option to reorder if necessary (0: Sunday, 1: Monday, etc). You can also set `isRTL` to `true` for languages that are read right-to-left.

Extensions
----------

[](#extensions)

### Timepicker

[](#timepicker)

Pikaday is a pure datepicker. It will not support picking a time of day. However, there have been efforts to add time support to Pikaday. See [\#1](https://github.com/dbushell/Pikaday/issues/1 "Issue 1") and [\#18](https://github.com/dbushell/Pikaday/issues/18 "Issue 18"). These reside in their own fork.

You can use the work [@owenmead](https://github.com/owenmead "@owenmead") did most recently at [owenmead/Pikaday](https://github.com/owenmead/Pikaday "Pikaday")A more simple time selection approach done by [@xeeali](https://github.com/xeeali "@xeeali") at [xeeali/Pikaday](https://github.com/xeeali/Pikaday "Pikaday") is based on version 1.2.0. Also [@stas](https://github.com/stas "@stas") has a fork [stas/Pikaday](https://github.com/stas/Pikaday "Pikaday"), but is now quite old

Browser Compatibility
---------------------

[](#browser-compatibility)

- IE 7+
- Chrome 8+
- Firefox 3.5+
- Safari 3+
- Opera 10.6+

[![browser compatibility](https://camo.githubusercontent.com/94c7c7c724145d338fe843dfa184305d0143c13c4b1718fdafdde6eb44ead466/68747470733a2f2f63692e746573746c696e672e636f6d2f72696b6b6572742f70696b616461792e706e67)](https://ci.testling.com/rikkert/pikaday)

---

Authors
-------

[](#authors)

- David Bushell [http://dbushell.com](http://dbushell.com/ "dbushell.com") [@dbushell](https://twitter.com/dbushell "@dbushell")
- Ramiro Rikkert [GitHub](https://github.com/rikkert "Rikkert GitHub") [@RamRik](https://twitter.com/ramrik "@ramrik")

Thanks to [@shoogledesigns](https://twitter.com/shoogledesigns/status/255209384261586944 "@shoogledesigns") for the name.

Copyright © 2014 David Bushell | BSD &amp; MIT license

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 52.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~212 days

Total

4

Last Release

3132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec417b24a084689d7cb17846a9fed926af0c95f14caf581b89f7fdc2c73e7316?d=identicon)[NiallSmyth](/maintainers/NiallSmyth)

---

Top Contributors

[![rikkert](https://avatars.githubusercontent.com/u/153894?v=4)](https://github.com/rikkert "rikkert (159 commits)")[![dbushell](https://avatars.githubusercontent.com/u/998922?v=4)](https://github.com/dbushell "dbushell (65 commits)")[![owenmead](https://avatars.githubusercontent.com/u/97622?v=4)](https://github.com/owenmead "owenmead (8 commits)")[![eadmundo](https://avatars.githubusercontent.com/u/38262?v=4)](https://github.com/eadmundo "eadmundo (8 commits)")[![leizhao4](https://avatars.githubusercontent.com/u/763847?v=4)](https://github.com/leizhao4 "leizhao4 (6 commits)")[![everdimension](https://avatars.githubusercontent.com/u/5347023?v=4)](https://github.com/everdimension "everdimension (6 commits)")[![pts-michaelvera](https://avatars.githubusercontent.com/u/23039188?v=4)](https://github.com/pts-michaelvera "pts-michaelvera (6 commits)")[![MoOx](https://avatars.githubusercontent.com/u/157534?v=4)](https://github.com/MoOx "MoOx (5 commits)")[![nathancahill](https://avatars.githubusercontent.com/u/1383872?v=4)](https://github.com/nathancahill "nathancahill (5 commits)")[![bquorning](https://avatars.githubusercontent.com/u/22333?v=4)](https://github.com/bquorning "bquorning (4 commits)")[![NiallSmyth](https://avatars.githubusercontent.com/u/209378?v=4)](https://github.com/NiallSmyth "NiallSmyth (3 commits)")[![elwayman02](https://avatars.githubusercontent.com/u/1325482?v=4)](https://github.com/elwayman02 "elwayman02 (3 commits)")[![stuart-bennett](https://avatars.githubusercontent.com/u/493995?v=4)](https://github.com/stuart-bennett "stuart-bennett (3 commits)")[![mattrobenolt](https://avatars.githubusercontent.com/u/375744?v=4)](https://github.com/mattrobenolt "mattrobenolt (2 commits)")[![noyainrain](https://avatars.githubusercontent.com/u/1292795?v=4)](https://github.com/noyainrain "noyainrain (2 commits)")[![jeroenbourgois](https://avatars.githubusercontent.com/u/202312?v=4)](https://github.com/jeroenbourgois "jeroenbourgois (2 commits)")[![radiac](https://avatars.githubusercontent.com/u/241712?v=4)](https://github.com/radiac "radiac (2 commits)")[![DylanFM](https://avatars.githubusercontent.com/u/14375?v=4)](https://github.com/DylanFM "DylanFM (2 commits)")[![ZeStrid3r](https://avatars.githubusercontent.com/u/6397443?v=4)](https://github.com/ZeStrid3r "ZeStrid3r (2 commits)")[![stuartmcfarlane](https://avatars.githubusercontent.com/u/695727?v=4)](https://github.com/stuartmcfarlane "stuartmcfarlane (2 commits)")

---

Tags

datecalendardatepicker

### Embed Badge

![Health badge](/badges/rhubarbphp-pikaday/health.svg)

```
[![Health](https://phpackages.com/badges/rhubarbphp-pikaday/health.svg)](https://phpackages.com/packages/rhubarbphp-pikaday)
```

###  Alternatives

[azuyalabs/yasumi

The easy PHP Library for calculating holidays

1.1k11.4M26](/packages/azuyalabs-yasumi)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[yohang/calendr

Object Oriented calendar management

465614.1k3](/packages/yohang-calendr)[punic/punic

PHP-Unicode CLDR

1542.9M29](/packages/punic-punic)[umulmrum/holiday

A PHP library to compute holidays. It's something :-)

92342.6k1](/packages/umulmrum-holiday)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
