note 55986 added to function.date
| From: | ThiagoMorettothiago{at}moretto dot eng dot br at osu1 dot php dot net | Date: | Fri, 19 Aug 2005 19:36:36 +0000 |
| Subject: | note 55986 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93913@lists.php.net to get a copy of this message | ||
<?php
// for bitwise operations... =]
define(D_YEAR, 1);
define(D_MONTH, 2);
define(D_WEEK, 4);
define(D_DAY, 8);
define(D_HOUR, 16);
define(D_MINUTE, 32);
define(D_SECOND, 64);
function difftimetostring($difftime, $Opt = 0)
{
if ($Opt == 0) $Opt = D_YEAR | D_MONTH | D_DAY | D_HOUR | D_MINUTE;
$diffstring = null;
$BissextFix = floor ($difftime / ((3600 * 24) * 366));
for($i=(date('Y') - $BissextFix); $i < date('Y'); $i++)
{
$x = 0 + ($i / 4);
if (($x - floor($x)) == 0)
$bissextyears ++;
}
if ($Opt & D_YEAR) {
$years = floor($difftime / (3600 * 24 * (365 + $bissextdays)));
$difftime = $difftime % (3600 * 24 * (365 + $bissextdays));
}
if ($Opt & D_MONTH) {
$months = floor($difftime / (3600 * 24 * ((365 + $bissextdays)/12)));
$difftime = $difftime % (3600 * 24 * ((365 + $bissextdays)/12));
}
if ($Opt & D_WEEK) {
$weeks = floor($difftime / (3600 * 24 * 7));
$difftime = $difftime % (3600 * 24 * 7);
}
if ($Opt & D_DAY) {
$days = floor($difftime / (3600 * 24));
$difftime = $difftime % (3600 * 24);
}
if ($Opt & D_HOUR) {
$hours = floor($difftime / 3600);
$difftime = $difftime % 3600;
}
if ($Opt & D_MINUTE) {
$minutes = floor($difftime / 60);
$difftime = $difftime % 60;
}
if ($Opt & D_SECOND) {
$seconds = $difftime;
}
$diff = array();
// Ano
if($years > 0 && $years > 1)
array_push($diff, $years . ' anos');
else if ($years == 1)
array_push($diff, ' 1 ano');
// Meses
if($months > 0 && $months > 1)
array_push($diff, $months . ' meses');
else if ($months == 1)
array_push($diff, $months . ' mês');
// Semanas
if($weeks > 0 && $weeks > 1)
array_push($diff, $weeks . ' semanas');
else if ($weeks == 1)
array_push($diff, '1 semana');
// Dias
if($days > 0 && $days > 1)
array_push($diff, $days . ' dias');
else if ($days == 1)
array_push($diff, '1 dias');
// Horas
if($hours > 0 && $hours > 1)
array_push($diff, $hours . ' horas');
else if ($hours == 1)
array_push($diff, '1 hora');
// Minutos
if($minutes > 0 && $minutes > 1)
array_push($diff, $minutes . ' minutos');
else if ($minutes == 1)
array_push($diff, '1 minutos');
// Segundos
if($seconds > 0 && $seconds > 1)
array_push($diff, $seconds . ' segundos');
else if ($seconds == 1)
array_push($diff, '1 segundo');
return implode(', ', $diff) . ' atrás';
}
$DiffDate = time() - mktime(13, 30, 23, 3, 22, 1998);
$DiffDateString = difftimetostring($DiffDate, 0);
echo $DiffDateString;
?>
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55986
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55986&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55986&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55986&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55986&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55986&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55986&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55986&report=yes
Search -- http://master.php.net/manage/user-notes.php