PDA

View Full Version : Get Months



giovannotti
14 May 2009, 7:37 AM
I would like to know if is possible to get the current month and the two previous ones with ext?

javarine
14 May 2009, 7:40 AM
I'm sure you can do that with just plain ol' javascript.

Var d = new Date();

var month = d.getCurrentMonth();

var last_month = month -1;

var month_before_last = month - 2;

Some code like that should get you what you want....

Animal
14 May 2009, 7:43 AM
And what if the "month" was 0?

last_month -1? OK?

http://extjs.com/deploy/ext-3.0-rc1.1/docs/?class=Date&member=add

javarine
14 May 2009, 7:49 AM
I'm sure you can write some custom function to handle that.



function workTheMonths(month){
if(month == -1){
return 12;
}
else if(month == -2){
return 11;
}

}

giovannotti
14 May 2009, 7:52 AM
throws d.getCurrentMonth is not a function

if the current moth = 0, the value to show for the past month must be 11.

javarine
14 May 2009, 8:02 AM
Oh, yeah.
d.getMonth() is the javascript function.


function whatIsLastMonth(month){
var last_month = month - 1;

if(last_month == -1 )
return 11;

}

You can do the same thing for the month before last.
Happy coding

Animal
14 May 2009, 8:02 AM
Mmmm yeah. Real lot of point to that.

javarine
14 May 2009, 8:09 AM
Thanks Nige:
It is my pleasure to spread the gospel of javascript according to Ext.
Catcha...

giovannotti
14 May 2009, 8:15 AM
Thanks, that work perfect

iamakimmer
14 May 2009, 10:28 AM
isn't this cleaner?

var d = new Date();
console.info(d.format('n'));
console.info(d.add(Date.MONTH, -1).format('n'));
console.info(d.add(Date.MONTH, -2).format('n'));