Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

showing difference between dates in minutes js

const today = new Date();
const endDate = new Date(startDate.setDate(startDate.getDate() + 7));
const days = parseInt((endDate - today) / (1000 * 60 * 60 * 24));
const hours = parseInt(Math.abs(endDate - today) / (1000 * 60 * 60) % 24);
const minutes = parseInt(Math.abs(endDate.getTime() - today.getTime()) / (1000 * 60) % 60);
const seconds = parseInt(Math.abs(endDate.getTime() - today.getTime()) / (1000) % 60); 
Comment

js calculate date difference

var DateDiff = {

    inDays: function(d1, d2) {
        var t2 = d2.getTime();
        var t1 = d1.getTime();

        return parseInt((t2-t1)/(24*3600*1000));
    },

    inWeeks: function(d1, d2) {
        var t2 = d2.getTime();
        var t1 = d1.getTime();

        return parseInt((t2-t1)/(24*3600*1000*7));
    },

    inMonths: function(d1, d2) {
        var d1Y = d1.getFullYear();
        var d2Y = d2.getFullYear();
        var d1M = d1.getMonth();
        var d2M = d2.getMonth();

        return (d2M+12*d2Y)-(d1M+12*d1Y);
    },

    inYears: function(d1, d2) {
        return d2.getFullYear()-d1.getFullYear();
    }
}

var dString = "May, 20, 1984";

var d1 = new Date(dString);
var d2 = new Date();

document.write("<br />Number of <b>days</b> since "+dString+": "+DateDiff.inDays(d1, d2));
document.write("<br />Number of <b>weeks</b> since "+dString+": "+DateDiff.inWeeks(d1, d2));
document.write("<br />Number of <b>months</b> since "+dString+": "+DateDiff.inMonths(d1, d2));
document.write("<br />Number of <b>years</b> since "+dString+": "+DateDiff.inYears(d1, d2));
Comment

PREVIOUS NEXT
Code Example
Javascript :: arraylist of characters 
Javascript :: access-control-allow-origin nodejs express 
Javascript :: fetch x-www-form-urlencoded 
Javascript :: mui typography bold 
Javascript :: javascript get number of elements in object 
Javascript :: jquery scroll to top 
Javascript :: javascript appendchild image node 
Javascript :: command to create react app 
Javascript :: puppeteer headless false 
Javascript :: modal.show jquery 
Javascript :: pick a random element from an array javascript 
Javascript :: vue3 cdn 
Javascript :: Extract number from string javascripy 
Javascript :: validate Alphabet Letter js 
Javascript :: yarn create react app 
Javascript :: how to limit decimal places in javascript 
Javascript :: javascript get css variable 
Javascript :: how to select html body in javascript 
Javascript :: autocomplete off using jquery 
Javascript :: jquery remove element by id 
Javascript :: js set important style 
Javascript :: strike react native 
Javascript :: disable input field from jquery 
Javascript :: iframe getelementbyid 
Javascript :: jquery show for 5 seconds 
Javascript :: select2 on change 
Javascript :: class onclick jqery 
Javascript :: jquery scroll to bottom 
Javascript :: iframe in react native 
Javascript :: js tolocalestring without seconds 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =