Search code examples
javascriptextjsdatefield

Subtracting days in new Date() in a view


I got this piece of code:

    xtype: 'datefield',
    editable: false,
    itemId: 'start-date-field',
    fieldLabel: 'Från',
    labelWidth: 50,
    format: 'Y-m-d',
    value: new Date(),
    disabled: true

and I'm trying to subtract some days from "new Date()" but my googlefu isn't good enought and this is probably easy enough for most people. I've tried new Date().getDay - 30 but that only generates an error.


Solution

  • xtype: 'datefield',
    editable: false,
    itemId: 'start-date-field',
    fieldLabel: 'Från',
    labelWidth: 50,
    format: 'Y-m-d',
    value: (function() {var lastMonth = new Date(); return lastMonth.setDate(lastMonth.getDate()-30), lastMonth;})(),
    disabled: true
    

    JSFiddle