Breaking Posts

6/trending/recent
Type Here to Get Search Results !

Percentage difference calculation in previous and currunt month in php

This is the tutorial for Percentage difference calculation in previous and currunt month in php.



 <?php

  date_default_timezone_set('UTC');


  $currentMonth = date('n'); // n returns the numeric representation of the month (1-12)

  $previousMonth = $currentMonth - 1;

  if ($previousMonth === 0) {

    $previousMonth = 12;

  }


  $currentValue = 100;

  $previousValue = 90;

  $difference = $currentValue - $previousValue;

  $percentageDifference = ($difference / $previousValue) * 100;


  echo "Current month: " . $currentMonth . "\n";

  echo "Percentage difference from previous month: " . $percentageDifference . "%\n";

?>

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.