0

I want to get the date of day - 1 or month -1 for example, how can I manage that?

For now I have that:

resolve: {
  data: function($route, $http, $filter) {
    var today = new Date();
    var formattedDate = $filter('date')(today, 'yyyyMMdd');
    return $http.get('./app/sources/stats/'+$route.current.params.mag+'/'+$route.current.params.mag+'_20170205.json').then(function(response) {
      return response.data;
    });
  }
}
5
  • "I want to get the date of day - 1 or month -1" – can you decrypt this? Commented Feb 10, 2017 at 11:49
  • you can use getDate() and getMonth() function what you are asking is unclear Commented Feb 10, 2017 at 11:50
  • try this docs.angularjs.org/api/ng/filter/date it might help you. Commented Feb 10, 2017 at 11:54
  • I prefer to work with moment.js Commented Feb 10, 2017 at 12:29
  • @VinodLouis Yep thx, I used getDate and it works! Commented Feb 10, 2017 at 14:06

2 Answers 2

1
var today = new Date();
var yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);

same goes for setMonth and getMonth

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

1 Comment

I also used the filter to get yyyyMMdd --> var previousDay = new Date(today); var formattedDate2 = $filter('date')(previousDay.setDate(today.getDate()-1), 'yyyyMMdd'); Thanks a lot!
0

This is what i did to add days in my project. Maybe this will help you!

var app = angular.module('my-app', []);
  app.controller("my-controller", function($scope) {
   $scope.name = "world";
   $scope.mydate = new Date("2016-08-16T15:10:10.530Z");
   var numberOfDaysToAdd = 5;
    $scope.newdate = $scope.mydate.setDate($scope.mydate.getDate() + numberOfDaysToAdd); 
  });

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.