2

I need to get the date one day after another date. I do :

$scope.date2.setDate($scope.date1.getDate()+1);

if   
$scope.date1 = 2015-11-27  

then 
$scope.date2 = 2015-11-28

It s ok,
but when 

$scope.date1 = 2015-12-02

 then 
 $scope.date2 = 2015-11-28 (ie tomorrow)

I don't understand why...

If anyone knows..

ozil
  • 6,930
  • 9
  • 33
  • 56
user1260928
  • 3,269
  • 9
  • 59
  • 105

2 Answers2

3

try this instead efficient simple pure JS

var todayDate = new Date();    
console.log(new Date().setDate(todayDate.getDate()+1));

so you will have that same Date type object and hence you don't need to go with moment.js

2

Use moment.js for this momentjs

var startdate = "2015-12-02";
var new_date = moment(startdate, "YYYY-MM-DD").add('days', 1);
var day = new_date.format('DD');
var month = new_date.format('MM');
var year = new_date.format('YYYY');
alert(new_date);
alert(day + '.' + month + '.' + year);
Kamal Kumar
  • 3,393
  • 2
  • 19
  • 15