Skip to content

Instantly share code, notes, and snippets.

@twosouth twosouth/duration.js
Last active Jun 27, 2018

Embed
What would you like to do?
Calculate duration between dates
var dt_1 = new Date('2018-06-11 03:10:14 AM'); // create date object 1 June 11, 2018 3:10:14 AM
var dt_2 = new Date('2018-06-11 11:17:23 PM'); // create date object 2 June 11, 2018 11:17:23 PM
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.YEAR) + " Years");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.MONTH) + " Months");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.DAY) + " Days");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.HOUR) + " Hours");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.MINUTE) + " Minutes");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.SECOND) + " Seconds");
dt_1 = new Date('2018-06-11 03:10:14 AM'); // create date object 1 June 11, 2018 3:10:14 AM
dt_2 = new Date('2019-06-19 11:17:23 PM'); // create date object 2 June 19, 2019 11:17:23 PM
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.YEAR) + " Years");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.MONTH) + " Months");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.DAY) + " Days");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.HOUR) + " Hours");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.MINUTE) + " Minutes");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.SECOND) + " Seconds");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.