Check if input date is in given range
<p>I have a form with a simple input type. I'm trying to define a function to check if the date is no more than 6 months older compared to date provided by the input type. 
I know i have to convert the String provided by the input in a Date object to make this comparison and then work on get methods of Date object, but i can't figure out how to do this.</p>

<p>Current code:</p>

<pre><code>$scope.compareDates = function(d1) {
        d1 = new Date(d1); //convert String into date Object                
        var d = new Date(); // today date           
        d.setYear(d.getFullYear());
        d.setMonth(d.getMonth() - 6);           

        if(d1 &gt; d ) {
            console.log("ok");
        } else {
            console.log("error");               
        }
    }   
</code></pre>

<p>EDIT:</p>

<p>I'm sorry, i forgot to add my input. Here it is:</p>

<pre><code>&lt;input class="form-control" type="text" placeholder="gg/mm/aaaa" ng-model="sStartDate" ng-change="change()"&gt;
</code></pre>

<p>Angular Controller:</p>

<pre><code>$scope.sStartDate = '';

$scope.change = function(){

    var startDt = $scope.sStartDate;
    $scope.compareDates(startDt);

}
</code></pre>