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..
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..
Share Improve this question edited Nov 27, 2015 at 10:42 ozil 7,1259 gold badges36 silver badges61 bronze badges asked Nov 27, 2015 at 10:23 user1260928user1260928 3,43910 gold badges67 silver badges111 bronze badges 8-
2
why don't you try javascript Date function and add days to it
addDays(1)
rather doing+1
– super cool Commented Nov 27, 2015 at 10:25 - 1 also i will suggest you to create JsFiddle or Stack's inbuilt snippet creator, so people can see the actual problem and provide better solution – Virendra Yadav Commented Nov 27, 2015 at 10:27
- I don't see any addDays in Javascript – user1260928 Commented Nov 27, 2015 at 10:28
- you can use moment.js for date calculations – Kamal Kumar Commented Nov 27, 2015 at 10:29
-
1
getDate()
gets the date for today. If you increment it, it will be tomorrow. Everything works as it is supposed. Your logic inside the code is wrong. – cezar Commented Nov 27, 2015 at 10:31
2 Answers
Reset to default 3try 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
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);