Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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

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

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

PREVIOUS NEXT
Code Example
Php :: laravel route not found 
Php :: deleting a database in phpmyadmin 
Php :: PHP Filters Advanced 
Php :: route group laravel 8 
Php :: PHP strcoll — Locale based string comparison 
Php :: laravel eloquent batch insert 
Php :: auto complete order 
Php :: permission for multisite in wp-config.php file 
Php :: add class to li 
Php :: PHP metaphone — Calculate the metaphone key of a string 
Php :: php get non unique values from array 
Php :: how to calculate position of student in class in laravel 
Php :: sample test tinker php artisan 
Php :: slim disable display error details 
Php :: wp functions ajax get 
Php :: woocommerce status change date 
Php :: remove rank math next prev canonical 
Php :: get git branch with php 
Php :: php csv to multirow array $_FILES 
Php :: auto complete order paid3 
Php :: php ffi get load average 
Php :: shorthand to assign multiple variable to same value in php 
Php :: laravel add model to polymorphic relationships 
Php :: no cache on browser back php 
Php :: change regards line laravel 
Php :: rebuild joomla menu 
Php :: Laravel 9 localization not working on live server 
Php :: symfony dump request headers 
Php :: school management system in codeigniter free download 
Php :: $request laravel undefined inside function query 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =