Hello, I would like to know how I can do a subtraction of two date objects . I have a date of birth variable and I want to subtract the current day in order to obtain the difference in years ...
var f = new Date();
var xf = (f.getDate() + "/" + (f.getMonth() +1) + "/" + f.getFullYear());
var xy = 1981-11-17;
var x = xf - xy; //¿se puede algo así?
document.write(x);
can i do something like this???
You can use the moment.js library
It is very easy to use and helps you with all these calculations.
https://momentjs.com
For example you can do it as follows:
Cheers!
if you add or subtract dates it must be in their format, you can also add/subtract days