Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

is date 1 day ago javascript

function daysSinceGivenDate (date) {
  const dateInSeconds = Math.floor((new Date().valueOf() - date.valueOf()) / 1000);
  const oneDayInSeconds = 86400;

  return (dateInSeconds / oneDayInSeconds) | 0; // casted to int
};

console.log(daysSinceGivenDate(new Date())); // 0
console.log(daysSinceGivenDate(new Date("January 1, 2022 03:24:00"))); // relative...
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #date #day #javascript
ADD COMMENT
Topic
Name
7+8 =