<?php


function getTotalDays($from_date, $to_date) {

    // Define the current date

    $current_date = time(); // Current Unix timestamp


    // Convert provided dates to Unix timestamps

    $from_date_timestamp = strtotime($from_date);

    $to_date_timestamp = strtotime($to_date);


    // If To date is greater than current date, set it to current date

    if ($to_date_timestamp > $current_date) {

        $to_date_timestamp = $current_date;

    }


    // Calculate the total days between From date and adjusted To date

    $total_days = floor(($to_date_timestamp - $from_date_timestamp) / (60 * 60 * 24)) + 1; // Add 1 to include both From date and To date


    return $total_days;

}


// Example usage

$from_date = '20-03-2024';

$to_date = '30-05-2024';


$total_days = getTotalDays($from_date, $to_date);

echo "Total days between From date and adjusted To date: " . $total_days . " days.\n";


?>


Comments

Popular posts from this blog

How to seperate character from string in php

How to Delete record using PHP Ajax

Uploads Only 10 files in month step by step