I tried to split data as below, but the error "dat.split is not a function" displays. Anyone know how can I solve this problem?
var dat = new Date("2009/12/12");
var r = dat.split('/');
I tried to split data as below, but the error "dat.split is not a function" displays. Anyone know how can I solve this problem?
var dat = new Date("2009/12/12");
var r = dat.split('/');
You can't split() a Date - you can split() a String, though:
var dat = "2009/12/12";
var r = dat.split('/');
returns:
["2009", "12", "12"]
To do the equivalent with a date, use something like this:
var dat = new Date();
var r = [dat.getFullYear(), dat.getMonth() + 1, dat.getDate()];
returns:
[2009, 4, 17]
try
dat.toString().split('/');
but this solution is locale dependent
new Date("2009/12/12").toString().split('/'); // ["Sat Dec 12 2009 00:00:00 GMT-0500 (Eastern Standard Time)"]