$scope.currentDate=new Date();
$scope.currentDate=$filter('date')(new Date(),'yyyy-MM-dd');
//Value received from web service stored in data
$scope.login=data.last_login_server;
$scope.login=$filter('date')($scope.login,'yyyy-MM-dd');
if(($scope.login.getDate() + 30) == $scope.currentdate)
alert('Time limit exceeded');
Asked
Active
Viewed 31 times
0

Pardeep Dhingra
- 3,916
- 7
- 30
- 56

Sourav Basu
- 21
- 2
-
4Use moment.js is the way to go – Callum Linington Feb 11 '16 at 08:40
-
I would also have this check done in the ui state change or the route change as well. That way you can pretty much prevent them from going anywhere – Callum Linington Feb 11 '16 at 08:41
-
What format is `last_login_server`? Can you create a `Date` from that? – hansmaad Feb 11 '16 at 08:45
-
use old fashioned javascript Date – Yerken Feb 11 '16 at 08:46
-
Here is one way answered in another post: http://stackoverflow.com/a/3224854/5872769 – Rumoch Feb 11 '16 at 08:49
1 Answers
0
You can get the ellapsed time in milliseconds from two dates.
var now = new Date();
var lastTime = new Date(/*data.last_login_server*/);
// set a date 30 days ago for demonstration
lastTime.setDate(now.getDate() - 30);
var milliseconds = (now - lastTime);
var days = milliseconds / 1000 / 3600 / 24;
alert(days);

hansmaad
- 18,417
- 9
- 53
- 94