PDA

View Full Version : How to get the date 30days before today with extjs Date type



evilight
10 Jan 2012, 12:48 AM
Hi all,

it's me again. :-?

in php or shell or unix c api, I can use code like
$sdate = date("Y-m-d",strtotime("today -30days"));
just tell them I want date "today -30days" ago to get the right answer.

how can I get this done in extJs4?

I only see following parameter to new a Date. and

newDate("December 19, 1989 03:24:00");any existing api to do above work or I have to do it all by myself?

Thank you in advance

tomearly
10 Jan 2012, 1:05 AM
Check out the documentation here http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Date for Ext.Date

There is an add method which can be used as follows



// Negative values will be subtracted
var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'

Therefore you would just do minus 30 days.

evilight
10 Jan 2012, 1:13 AM
Thank you.
And I also find another solution

var def_edate = new Date();
var tmp_date = new Date();
tmp_date.setDate(tmp_date.getDate()-30);
var def_sdate = tmp_date;