How to subtract some years from current date in angular js, I am trying to validate DOB field, what i see in gmail validation is it is accepting 3 years back from current date so how to subtract some years from current date in angular js
Asked
Active
Viewed 1,849 times
0
-
Related: http://stackoverflow.com/questions/674721/how-do-i-subtract-minutes-from-a-date-in-javascript – Fidel90 Apr 15 '16 at 09:57
-
That's what i was asking i can subtract two date variables but how to calculate it some years back from current date is the question – Sultan Apr 15 '16 at 10:04
-
And that's what the other thread anwered already, as far as I understood your problem. See my answer for an example. – Fidel90 Apr 15 '16 at 10:48
2 Answers
0
There are several good answers on this question, How to subtract two angularjs date variables, that can help you.
0
Well, below is a pure JS solution:
var nowInMS = new Date().getTime(),//get the current time and convert to milliseconds
threeYearsInMS = 1000 * 60 * 60 * 24 * 365 * 3,//calculate the amount of milliseconds in three years
threeYearsBeforeNow = new Date(nowInMS - threeYearsInMS);//build a new date after subtracting
alert(threeYearsBeforeNow);//voila

Fidel90
- 1,828
- 6
- 27
- 63