1

i have an array of date. got it from mysql database and already converted to js date. the date i got from db are converted to string date like this.

I've read from this about php to js date : Send PHP date to javascript date Format

let say this is the php date that i use ajax and got response

data = ["Sun Apr 27 2014 22:14:25 +0100","Thu May 29 2014 22:14:25 +0100"]

i have a global namespace. var myDate = {};

the data array was converted to js date like this:

var arr = [];
$.each(data, function(k,v){
    arr.push = new Date(v);
});
myDate.list = arr;

this is the bootstrap datepicker code:

$('#bdate').datepicker('setDates', myDate.list);

addtitional info: I'm using <div id="bdate"></div> so it will display an inline datepicker

the issue is it seems to be not setting the dates on the picker.

here is the fiddle: http://jsfiddle.net/faiz_qlo/jPphC/

Community
  • 1
  • 1
faiz
  • 123
  • 5
  • 16
  • Are you set date format to datepicker? http://stackoverflow.com/questions/1953840/datepickersetdate-issues-in-jquery – umut May 24 '14 at 22:01
  • that one is for normal `jquery`, `jquery-ui`. i am using `bootstrap-datepicker`. i don't think its the same – faiz May 24 '14 at 22:05

1 Answers1

2

yes! finally. i got it to work!

var myDate = [];
var data = ["Sun Apr 27 2014 22:14:25 +0100","Thu May 29 2014 22:14:25 +0100"];
var arr = [new Date(2014,05,01), new Date(2014,05,04)]; // just testing

$.each(data, function(k, v){
  var nd = new Date(v);
  var ndd = nd.getDate()-1;
  var ndm = nd.getMonth()+1;
  var ndy = nd.getFullYear();
  var ndg = [parseInt(ndy), parseInt(ndm), parseInt(ndd)];
  myDate.push(new Date(ndg));
  $('#log').append('<div>'+myDate+'</div>');
});

$('#bdate').datepicker('setDates', myDate);

here is the fiddle
http://jsfiddle.net/faiz_qlo/jPphC/1/

faiz
  • 123
  • 5
  • 16