0

Have a form, need to pass three days from the current date. I wrote the following code which does not work

var fb_form_end_date = {
  xtype : 'hidden',
  name  : 'PLAN_DATE_END',
  value : ((new Date()).getData()+3).format('d-m-Y')
}

I know that it is possible to use this solution:

var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate()+3);
var fb_form_end_date = {
      xtype : 'hidden',
      name  : 'PLAN_DATE_END',
      value : tomorrow
    }

but is it possible to do everything on a single line without any extra definitions?

using extjs 3.4

4 Answers 4

2

You can try this :

var fb_form_end_date = {
  xtype : 'hidden',
  name  : 'PLAN_DATE_END',
  value : new Date().add(Date.DAY, 3)
}

Here is the reference to Ext Docs

Sign up to request clarification or add additional context in comments.

Comments

1

I believe this should work. It's more accurate than simply adding 3 to .getDate() because that approach could give you days that don't actually exist in the month, like the 32nd. It also doesn't depend on any libraries.

new Date(Date.now()+86400000*3)

So in your code it would look like:

var fb_form_end_date = {
      xtype : 'hidden',
      name  : 'PLAN_DATE_END',
      value : new Date(Date.now()+86400000*3)
    }

Comments

0

try this

var fb_form_end_date = {
       xtype : 'hidden',
       name  : 'PLAN_DATE_END',
       value : (new Date((new Date()).setDate((new Date()).getDate() + 3))).format('d-m-Y')
   }   

Comments

0

For completeness. Other answers refer to Date.add() and Date.format() neither of which exist in vanilla javascript. If you really wanted this all on one line for some reason and couldn't define your own variables other than the object itself then this would do it:

var fb_form_end_date = {
    xtype : 'hidden',
    name  : 'PLAN_DATE_END',
    value : (function() { var d = new Date(new Date().getTime() + 86400000*3); return d.getDate() + '-' + d.getMonth() + '-' + d.getFullYear();})();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.