Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to get the difference (in days) between two dates?

const getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
  (dateFinal - dateInitial) / (1000 * 3600 * 24);

// Example
getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9
Comment

best way to get the number of days between these two dates

best way to get the number of days between these two dates

from datetime import date

d0 = date(2008, 8, 18)
d1 = date(2008, 9, 26)
delta = d1 - d0
print(delta.days)
Comment

Days between Two Dates

const dayDif = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000)

dayDif(new Date("2020-10-21"), new Date("2021-10-22"))
// Result: 366
Comment

get number of days between two dates

nbr_days = 365*year + year/4 - year/100 + year/400 + date + (153*month+8)/5
Comment

#find the difference in days between two dates.

#Find the difference in days between two dates.

from datetime import date
start_date = date(2022, 1, 10)
end_date = date(2022, 11, 10)
(end_date - start_date).days

304
Comment

different between two dates

<?php
$date2='2022-08-1 2:10:00';
date_default_timezone_set('Asia/Karachi');
    $date1 = date("Y-m-d H:i:s");
    $timestamp1 = strtotime($date1);
    $timestamp2 = strtotime($date2);
    $posted_time_hours  = round((abs($timestamp2 - $timestamp1))/(60*60)) ;
    if(($posted_time_hours) >= 24){ 
        $posted_time_hours = round($posted_time_hours/24) . " day(s) ago";
    }
    else{

         $posted_time_hours =  $posted_time_hours . " hour(s) ago";
    }
    echo $posted_time_hours;
?>
Comment

get days between two dates

// new Date("dateString") is browser-dependent and discouraged, so we'll write
// a simple parse function for U.S. date format (which does no error checking)
function parseDate(str) {
    var mdy = str.split('/');
    return new Date(mdy[2], mdy[0]-1, mdy[1]);
}

function datediff(first, second) {
    // Take the difference between the dates and divide by milliseconds per day.
    // Round to nearest whole number to deal with DST.
    return Math.round((second-first)/(1000*60*60*24));
}

alert(datediff(parseDate(first.value), parseDate(second.value)));
Comment

PREVIOUS NEXT
Code Example
Javascript :: upload image to server next js 
Javascript :: How to pass variables from js to html node 
Javascript :: javascript pure ajax 
Javascript :: javascript push and concat 
Javascript :: Conditionally pass props to react component 
Javascript :: cypress wait object to change 
Javascript :: jquery create array 
Javascript :: node 10 form data 
Javascript :: shorthand if statement js 
Javascript :: how to add multiple styles in javascript 
Javascript :: pass data from child component to parent component 
Javascript :: children array javascript 
Javascript :: javascript get object where 
Javascript :: string padStart padEnd 
Javascript :: Function is not defined - Uncaught ReferenceError 
Javascript :: variables in js 
Javascript :: dynamic regex javascript 
Javascript :: js array pop 
Javascript :: pylint vscode disable max line length 
Javascript :: how to copy an arry react 
Javascript :: sort array without changing the original js 
Javascript :: how to replace div element with another in javascript 
Javascript :: mongoose update subdocument by id 
Javascript :: function to generate random number in javascript 
Javascript :: javascript trigger keypress 
Javascript :: JavaScript throw with try...catch 
Javascript :: javascript alert variable 
Javascript :: how to get csrf token in javascript 
Javascript :: React native calender date picker 
Javascript :: javasciprt set cookie 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =