I want to get "day of the week" from specific date in angular binding. Expected result like:
date=07/26/2017
so above date day is "wednesday"
expected result is "3" b'coz above date weekDay is "3"
I want to get "day of the week" from specific date in angular binding. Expected result like:
date=07/26/2017
so above date day is "wednesday"
expected result is "3" b'coz above date weekDay is "3"
you can try this:
var t = new Date('07/26/2017')
t.getDay() // it will return 3
This is a working snippet:
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myDate = '07/26/2017';
});
app.filter('customdate', function() {
return function(input) {
var t = new Date(input);
return t.getDay();
}
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
{{myDate|customdate}}
</div>
You can use simple date prototype methods like getDay()
Here is the example.
var d = new Date('07/26/2017');
var day = d.getDay()'
It will simple return 3
i.e. day of the week.
NOTE: Date constructor should be initialized with the standard date formats.
Here, you can try this.
<div ng-app="dateApp" ng-controller="dateController">
<p> {{ result }} </p>
</div>
Controller
var dtApp = angular.module('dateApp', []);
dtApp.controller(
'dateController',
function ($scope, $filter) {
$scope.result = new Date().getDay();
}
);