Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get date of one day before in extjs field

Tags:

date

extjs

I have the following date field i want to get date of one day before , how can i get that ? In my form panel

 items: [{
    fieldLabel: 'Start Date',
    name: 'fromdate',
    ref: '../fromdate',
    id: 'fromdate',
    vtype: 'daterange',
    value: new Date(),
    endDateField: 'todate' // id of the end date field
}, {
    fieldLabel: 'End Date',
    name: 'todate',
    id: 'todate',
    vtype: 'daterange',
    value: new Date(),
    startDateField: 'fromdate' // id of the start date field
}]

Today I am getting 03/23/2011 but I want 03/22/2011 How I can get 03/22/2011?

like image 972
XMen Avatar asked Dec 06 '25 04:12

XMen


2 Answers

Speaking ExtJS language, you can use Ext.Date library for manipulation dates. For example:

        Ext.Date.add (new Date(),Ext.Date.DAY,1)

Depending on your code logic, you can modify the default value of date field by several ways:

1) In the item's value configuration:

        {
            ...
            vtype: 'daterange',
            value : Ext.Date.add (new Date(),Ext.Date.DAY,1),
            fromDateField: 'fromdate',
            ...
        }

2) During the component's event. Basically, ExtJS containers have initComponent method which is the most first running, but be sure to set your code after callParent() method in order to access items collection. Example:

initComponent: function() {
            ...
    this.callParent(arguments);
            this.items.getByKey('fromdate').value = Ext.Date.add (new Date(),Ext.Date.DAY,1);
            ...
}
like image 107
sna19 Avatar answered Dec 09 '25 23:12

sna19


Try this:

new Date().add(Date.DAY, -1);
like image 37
Tom Micheline Avatar answered Dec 10 '25 01:12

Tom Micheline



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!