0

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"
nativegrip
  • 892
  • 10
  • 20
  • 1
    Possible duplicate of [Get the weekday from a Date object or date string using JavaScript](https://stackoverflow.com/questions/17964170/get-the-weekday-from-a-date-object-or-date-string-using-javascript) – Vivz Jul 26 '17 at 06:54
  • i tried
    It return result in day name like "Sun-Sat" format but i expect result in week day number.
    – nativegrip Jul 26 '17 at 06:55

3 Answers3

2

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>
Gaurav Srivastava
  • 3,232
  • 3
  • 16
  • 36
0

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.

Arun Redhu
  • 1,584
  • 12
  • 16
0

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();
    }
);
Arun Banik
  • 470
  • 4
  • 9