0

When endate is selected, the value of edate works fine, however I want to add one day to selected date before sending request to controller.

code to get value from datepicker:

var edate = $("#in_edate").datepicker({ dateFormat: 'dd/mm/yy' }).val();

Code to add one day to current value if not null:

if (edate != null) edate = moment(edate).add(1, 'days').toDate();

the problem is that edate return like Date {Thu Mar 03 2016 00:00:00 GMT+0800 (Malay Peninsula Standard Time)} and also does not add one day ?

I do not understand why date format became long format and why one day is not added to the selected date.

Saif
  • 2,611
  • 3
  • 17
  • 37

1 Answers1

0

You should be using .format() with Moment, as it looks like you are expecting a formatted string, not a Date object. The difference in days may be explained by timezones or improper parsing of the dates. Make sure when you pick '10 March' in the datepicker you're not getting back '3 October'.

if (!edate) edate = moment(edate, 'DD/MM/YY').add(1, 'days').format('DD/MM/YY');

http://momentjs.com/docs/#/displaying/

BeaverusIV
  • 988
  • 1
  • 11
  • 26
  • it add one month not one day. selected date like is `01/03/2016` but I am getting `04/01/2016` – Saif Feb 16 '16 at 04:18
  • @Smart exactly. You are not telling Moment how to parse the date properly. Once you do that it will add a day instead of a month. It will be parsing it in the USA time format of mm/dd/yyyy whereas you want dd/mm/yyyy. – BeaverusIV Feb 16 '16 at 04:35
  • @Smart I've added in the parsing code in my example in case you didn't know how to do it. – BeaverusIV Feb 16 '16 at 04:37