Example 1: date difference in number of days sql server
DECLARE
@start_dt DATETIME2= '2019-12-31 23:59:59.9999999',
@end_dt DATETIME2= '2020-01-01 00:00:00.0000000';
SELECT
DATEDIFF(year, @start_dt, @end_dt) diff_in_year,
DATEDIFF(quarter, @start_dt, @end_dt) diff_in_quarter,
DATEDIFF(month, @start_dt, @end_dt) diff_in_month,
DATEDIFF(dayofyear, @start_dt, @end_dt) diff_in_dayofyear,
DATEDIFF(day, @start_dt, @end_dt) diff_in_day,
DATEDIFF(week, @start_dt, @end_dt) diff_in_week,
DATEDIFF(hour, @start_dt, @end_dt) diff_in_hour,
DATEDIFF(minute, @start_dt, @end_dt) diff_in_minute,
DATEDIFF(second, @start_dt, @end_dt) diff_in_second,
DATEDIFF(millisecond, @start_dt, @end_dt) diff_in_millisecond;
Example 2: sql get number of days between two dates
DATEDIFF(DAY, '1/1/2011', '3/1/2011')
Example 3: difference in dates sql
SELECT (END_DATE - START_DATE) Days-Total FROM MyTable
Example 4: date difference
function daysBetween(first, second) {
var one = new Date(first.getFullYear(), first.getMonth(), first.getDate());
var two = new Date(second.getFullYear(), second.getMonth(), second.getDate());
var millisecondsPerDay = 1000 * 60 * 60 * 24;
var millisBetween = two.getTime() - one.getTime();
var days = millisBetween / millisecondsPerDay;
return Math.floor(days);
}