I want to add 'Last Year' option in daterangepicker.jQuery.js which will show me date start from- 1/1/2009 to 12/1/2009 (mm/dd/yyyy). how can i add this functionality in js file.
A:
The daterangepicker have a presetRanges object you can dynamically set.
In your case for example:
$('input').daterangepicker( {
presetRanges: [
{text: 'last year', dateStart: '01.01.09', dateEnd: '01.01.10' }
]
} );
Obviously, you can use any Date. you can also use Date.js or javascript Date() to dynamically get the dates.
With Date.js it is super easy: http://code.google.com/p/datejs/ (see the "Syntax Overview").
yn2
2010-01-12 09:20:50
we can put this in daterangepicker.jQuery.js but my problem is i want date start and dateEnd dynamical, every year i cant change my code
Pankaj
2010-01-12 09:23:41
@Pankaj - checkout my answer to achieve what you want.
Krunal
2010-01-12 09:31:05
@Pankaj, Krunal Mevada answer is just what you need!
yn2
2010-01-12 10:11:45
+2
A:
Solution:
Just add following preset range code to your daterangepicker js.
presetRanges: [
{ text: 'Last Year', dateStart: function() { var x = Date.parse('1 year ago'); x.setMonth(0); x.setDate(1); return x; }, dateEnd: function() { var x = Date.parse('1 year ago'); x.setMonth(11); return x.moveToLastDayOfMonth(); }}
]
Krunal
2010-01-12 09:30:14