Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap datepicker - Parse date

I'm using the pretty good eternicode's/bootstrap-datepicker jQuery plugin.

I'm trying to use the included DPGlobal tools to do some date operations.

Example:

dpg = $.fn.datepicker.DPGlobal;
date_format = 'dd/mm/yyyy';
date_str = '31/12/2013';
console.log(dpg.parseDate(start, date_format));

returns me (on firefox)

TypeError: format.parts is undefined

What am I doing wrong ?


Check out my fiddleable example

like image 510
Pierre de LESPINAY Avatar asked Apr 05 '13 13:04

Pierre de LESPINAY


2 Answers

You also have to parse the format before you use parseDate(...) :) .

dpg.parseDate(date_str, dpg.parseFormat(date_format))

I've updated your fiddle.

like image 108
Eich Avatar answered Nov 20 '22 23:11

Eich


You need to parse the format first using parseFormat(format)

$('body').append($('<div />').text(dpg.parseDate(date_str, dpg.parseFormat(date_format))));

Demo: Plunker

like image 37
Arun P Johny Avatar answered Nov 20 '22 22:11

Arun P Johny