How to set the date in materialize datepicker

Materialize datepicker is a modified pickadate.js picker.

Accodging to their API docs, this is how to set the picker:

  1. Get the picker:
var $input = $('.datepicker').pickadate()

// Use the picker object directly.
var picker = $input.pickadate('picker')
  1. Set the date:
// Using arrays formatted as [YEAR, MONTH, DATE].
picker.set('select', [2015, 3, 20])

// Using JavaScript Date objects.
picker.set('select', new Date(2015, 3, 30))

// Using positive integers as UNIX timestamps.
picker.set('select', 1429970887654)

// Using a string along with the parsing format (defaults to `format` option).
picker.set('select', '2016-04-20', { format: 'yyyy-mm-dd' })

Leave a Comment