Add Days to JavaScript Date in AngularJS

Last Reply one month ago By dharmendr

Posted one month ago

Hi,

i have one gridview

after loading of page need to dispaly next 30days from today date 

could you please help me

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js"></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', [])
        app.controller('MyController', function ($scope, $http, $window) {
            $scope.Details = [{ Date: new Date(),Name: '' }];
        });
    </script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
    <table id="tblOrders" class="table table-responsive">
        <tr>
            <th>Name</th>
            <th>Date</th>
        </tr>
        <tbody ng-repeat="detail in Details">
            <tr>
                <td><input type="text" ng-model="detail.Name" /></td>
                <td>
                    <input type="date" ng-model="detail.Date"  />
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>
You are viewing reply posted by: dharmendr one month ago.
Posted one month ago Modified on one month ago

Hi mahesh213,

Check this example. Now please take its reference and correct your code.

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js"></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', [])
        app.controller('MyController', function ($scope, $http, $window) {
            $scope.Details = [{ Date: new Date(), Name: ''}];
            for (var i = 0; i < $scope.Details.length; i++) {
                $scope.Details[i].Date = $scope.Details[i].Date.addDays(30);
            }
        });

        Date.prototype.addDays = function (num) {
            var value = this.valueOf();
            value += 86400000 * num;
            return new Date(value);
        }
    </script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
    <table id="tblOrders" class="table table-responsive">
        <tr>
            <th>Date</th>
        </tr>
        <tbody ng-repeat="detail in Details">
            <tr>
                <td><input type="date" ng-model="detail.Date" /></td>
            </tr>
        </tbody>
    </table>
</body>
</html>

Demo