Home > 2011, internet, News, OFFER, Open-source, PHP > To calculate the Difference between the date in php

To calculate the Difference between the date in php

function dbDateDiff($d)
{
$ts = time() – @strtotime(str_replace(“-“,”/”,$d));
if($ts>31536000) $val = round($ts/31536000,0).’ year’;
else if($ts>2419200) $val = round($ts/2419200,0).’ month’;
else if($ts>604800) $val = round($ts/604800,0).’ week’;
else if($ts>86400) $val = round($ts/86400,0).’ day’;
else if($ts>3600) $val = round($ts/3600,0).’ hour’;
else if($ts>60){ $val = round($ts/60,0).’ minute’;
//print “<br>$val<br>”;
}else $val = $ts.’ second’;
if($val>1) $val .= ‘s’;
return $val;
}

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: