Aug 21

function get_day_before(date){

var bits = date.split(‘-‘);
var d = new Date(bits[0], (bits[1]-1), bits[2]);
var date = new Date(d.setDate(d.getDate() – 1));
var year = date.getFullYear();
var month = date.getMonth()+1;
var day= date.getDate();
if(month<10) month=’0’+month;
if(day<10) day=’0’+day;

alert(year+”-“+month+”-“+day);
}

use: get_day_before(“2012-08-09”);
will return: 2012-08-08

written by MG \\ tags: , ,