-1

I have this simple javascript function to sum a date

    console.log(this.state.birth_date)  //logs birth date

    var death_date = this.state.birth_date.setFullYear(this.state.birth_date.getFullYear() + this.state.years_to_live) 

    console.log(this.state.birth_date) //logs death date
    console.log(death_date) //logs death date

How to avoid the birth date being set as death date after the death date is set?

mouchin777
  • 1,428
  • 1
  • 31
  • 59
  • 1
    Does this answer your question? [How to clone a Date object?](https://stackoverflow.com/questions/1090815/how-to-clone-a-date-object) – ASDFGerte Jan 10 '20 at 15:29

1 Answers1

1
var birth = new Date();
var death = new Date(birth.getTime())

death.setFullYear(birth.getFullYear() + 100);

console.log('Birth: ' + birth);
console.log('Death: ' + death);
Brant
  • 1,764
  • 11
  • 18