0

I am trying to get a correct outcome on difference of two dates. But when I do this I am getting a result such as (ex.10211438742389) instead of 1, 2, 3, 4, etc.. This is my JavaScript code.

import Division from '@salesforce/schema/User.Division';
import { LightningElement, track } from 'lwc';

export default class LightningExampleInputDate extends LightningElement {

    @track date1;
    @track date2;
    @track result;


    datehandler1(event) {
        this.date1 = Date.now();
        console.log(event.target.value)
    }
    datehandler2(event) {
        this.date2 = new Date(event.target.value);
        console.log(event.target.value);
    }
    resulthandler() {
        this.result = Math.abs(this.date2 - this.date1);
        console.log(this.result);
    }
}

I am expecting a shorter value to come out when I check the difference in-between two dates.

kemicofa ghost
  • 16,349
  • 8
  • 82
  • 131

1 Answers1

0

Dates in javascripts is a representation of milliseconds starting from the epoch date, which is 1st of Jan 1970.

If you want to calculate the difference of two dates in days, you could try this solution: https://stackoverflow.com/a/3224854/1964104

lchennl
  • 1
  • 2