Friday, July 29, 2011

Calculate time-diff and calculate age from birth date

On my searches I've found many many different, complicated functions for time difference and many different functions calculate age, But for such a simple task I thought there should be a simpler solution.
so here are a few good simple ways to calculate time differences and age

good and simple function that because of the versatility of strtotime function can support many different date formats:

function dateDiff($from, $to = "now")
{
return round((strtotime($to) - strtotime($from))/60/60/24);
}

and if age calculation is what you desire,
a simple function to calculate age by birth date

/**
* Calc age from MySQL date format
* @param string $date YY-mm-dd (MySQL Date Format)
*/
function calcAge($date)
{
//Break the date into an array
list($Y,$m,$d) = explode("-",$date);
//Calculate Year Diff
$age = date("Y")-$Y;
//Subtract a year if exact birth date hasn't passed yet
if(date("md") < $m.$d) $age--;
//And finally return the age
return $age;
}

2 comments:

  1. Experience seamless trading with the WinProFX Forex Trading Platform, designed to empower traders of all experience levels. Access global currency markets with fast trade execution, advanced charting tools, real-time market data, and an intuitive interface that makes trading simple and efficient. Whether you're trading major, minor, or exotic currency pairs, WinProFX provides the technology, security, and support you need to make informed decisions. Take control of your trading journey with a reliable platform built for performance, flexibility, and success.
    Contact us Address — 1st Floor, The Sotheby Building, Rodney Bay, Gros-Islet, SAINT Lucia P.O Box 838, Castries, Saint Lucia Phone no — +97144471894 Website — https://winprofx.org/

    ReplyDelete
  2. Consistent performance in currency markets requires rigorous trade planning, measured leverage use, and absolute equity preservation. Fundedfirm provides traders worldwide with high-speed order execution, tight spreads, and transparent scaling programs designed to accelerate professional prop careers. To stay well within maximum loss thresholds and prevent unintended margin breaches during high-volatility events, adopting an interactive Forex Margin Calculator is essential for calculating exact position sizing, required margin reserves, and total trade exposure before entering market orders. By removing margin guesswork and managing risk with mathematical precision, Fundedfirm equips you to pass evaluation stages easily and scale your funded account safely.

    Forex Margin Calculator

    ReplyDelete