A cleaner example (half the comparisons) of distanceOfTimeInWords() function below:
<?php
public static function distanceOfTimeInWords($fromTime, $toTime = 0, $showLessThanAMinute = false) {
$distanceInSeconds = round(abs($toTime - $fromTime));
$distanceInMinutes = round($distanceInSeconds / 60);
if ( $distanceInMinutes <= 1 ) {
if ( !$showLessThanAMinute ) {
return ($distanceInMinutes == 0) ? 'less than a minute' : '1 minute';
} else {
if ( $distanceInSeconds < 5 ) {
return 'less than 5 seconds';
}
if ( $distanceInSeconds < 10 ) {
return 'less than 10 seconds';
}
if ( $distanceInSeconds < 20 ) {
return 'less than 20 seconds';
}
if ( $distanceInSeconds < 40 ) {
return 'about half a minute';
}
if ( $distanceInSeconds < 60 ) {
return 'less than a minute';
}
return '1 minute';
}
}
if ( $distanceInMinutes < 45 ) {
return $distanceInMinutes . ' minutes';
}
if ( $distanceInMinutes < 90 ) {
return 'about 1 hour';
}
if ( $distanceInMinutes < 1440 ) {
return 'about ' . round(floatval($distanceInMinutes) / 60.0) . ' hours';
}
if ( $distanceInMinutes < 2880 ) {
return '1 day';
}
if ( $distanceInMinutes < 43200 ) {
return 'about ' . round(floatval($distanceInMinutes) / 1440) . ' days';
}
if ( $distanceInMinutes < 86400 ) {
return 'about 1 month';
}
if ( $distanceInMinutes < 525600 ) {
return round(floatval($distanceInMinutes) / 43200) . ' months';
}
if ( $distanceInMinutes < 1051199 ) {
return 'about 1 year';
}
return 'over ' . round(floatval($distanceInMinutes) / 525600) . ' years';
}
?>
time
(PHP 4, PHP 5)
time — Return current Unix timestamp
Popis
int time ( void )Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
Příklady
Příklad 342. time() example
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
// 7 days; 24 hours; 60 mins; 60secs
echo 'Now: '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
// or using strtotime():
echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n";
?>
Výše uvedený příklad vypíše něco jako:
Now: 2005-03-30
Next Week: 2005-04-06
Next Week: 2005-04-06
Poznámky
Tip
Timestamp of the start of the request is available in $_SERVER['REQUEST_TIME'] since PHP 5.1.
Viz také
| date() |
| microtime() |
time
Anonymous
01-Sep-2008 05:30
01-Sep-2008 05:30
Jeremiah Peterson
18-Aug-2008 06:55
18-Aug-2008 06:55
I took a different approach to a time difference. The current functions provided to not account for the different number of days in a month.
I have included a function that will calculate the start dates month and the number of days in each month thereafter. There are two things that I have
not yet taken into account. One is daylight savings time and the other is leap year. Perhaps someone can add that to this code.
function num_months($mon_start, $months, $work) {
while($work > 2419200) {
switch($mon_start) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
if($work > 2678400) {
$work = $work - 2678400;
$mon_start++;
$months++;
} else {
$exit = 1;
}
break;
case 12:
if($work > 2678400) {
$work = $work - 2678400;
$mon_start = 1;
$months++;
} else {
$exit = 1;
}
break;
case 2:
$work = $work - 2419200;
$mon_start++;
$months++;
break;
case 4:
case 6:
case 9:
case 11:
if($work > 2592000) {
$work = $work - 2592000;
$mon_start++;
$months++;
} else {
$exit = 1;
}
break;
}
if($exit == 1) {
break;
}
}
return Array($months,$work);
}
$month_start = 9;
$day_start = 18;
$year_start = 2007;
$hour_start = 17;
$min_start = 25;
$sec_start = 0;
$start = gmmktime($hour_start,$min_start,$sec_start,
$month_start,$day_start,$year_start);
$yys = (365*24*60*60);
$wks = (7*24*60*60);
$dys = (24*60*60);
$hrs = (60*60);
$mns = (60);
$now = time();
$diff = $now - $start;
$work = $diff;
$years = (int)($work / $yys);
$work = $work - $years*$yys;
$total_years = pstr($years,"year",0);
$months = 0;
list($months, $work) = num_months($month_start, $months, $work);
$total_months = pstr($months,"month",0);
$weeks = (int)($work / $wks);
$work = $work - $weeks*$wks;
$total_weeks = pstr($weeks,"week",0);
$days = (int)($work / $dys);
$work = $work - $days*$dys;
$total_days = pstr($days,"day",0);
$hours = (int)($work / $hrs);
$work = $work - $hours*$hrs;
$total_hours = pstr($hours,"hour",0);
$mins = (int)($work / $mns);
$work = $work - $mins*$mns;
$total_mins = pstr($mins,"minute",0);
$secs = $work;
$total_secs = pstr($secs,"second",".");
print "Difference is $total_years $total_months $total_weeks
$total_days $total_hours $total_mins $total_secs.<br />";
?>
delgado dot enrique at gmail dot com
18-Aug-2008 06:34
18-Aug-2008 06:34
Remember to remove "$this->" from the wrapper function below if you are not placing both functions below within the same class.
delgado dot enrique at gmail dot com
15-Aug-2008 01:46
15-Aug-2008 01:46
So I was looking for an equivalent of Ruby on Rails time_ago_in_words function. I found the TimeAgo function in the comments here, but it doesn't quite behave like the Rails counterpart.
In case you are looking or it as well, I've ported the Ruby code into PHP. Unfortunately, it doesn't look as clean as its Ruby counterpart, but it works the same:
<?php
/*
* PHP port of Ruby on Rails famous distance_of_time_in_words method.
* See http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html for more details.
*
* Reports the approximate distance in time between two timestamps. Set include_seconds
* to true if you want more detailed approximations.
*
*/
function distanceOfTimeInWords($from_time, $to_time = 0, $include_seconds = false) {
$distance_in_minutes = round(abs($to_time - $from_time) / 60);
$distance_in_seconds = round(abs($to_time - $from_time));
if ($distance_in_minutes >= 0 and $distance_in_minutes <= 1) {
if (!$include_seconds) {
return ($distance_in_minutes == 0) ? 'less than a minute' : '1 minute';
} else {
if ($distance_in_seconds >= 0 and $distance_in_seconds <= 4) {
return 'less than 5 seconds';
} elseif ($distance_in_seconds >= 5 and $distance_in_seconds <= 9) {
return 'less than 10 seconds';
} elseif ($distance_in_seconds >= 10 and $distance_in_seconds <= 19) {
return 'less than 20 seconds';
} elseif ($distance_in_seconds >= 20 and $distance_in_seconds <= 39) {
return 'half a minute';
} elseif ($distance_in_seconds >= 40 and $distance_in_seconds <= 59) {
return 'less than a minute';
} else {
return '1 minute';
}
}
} elseif ($distance_in_minutes >= 2 and $distance_in_minutes <= 44) {
return $distance_in_minutes . ' minutes';
} elseif ($distance_in_minutes >= 45 and $distance_in_minutes <= 89) {
return 'about 1 hour';
} elseif ($distance_in_minutes >= 90 and $distance_in_minutes <= 1439) {
return 'about ' . round(floatval($distance_in_minutes) / 60.0) . ' hours';
} elseif ($distance_in_minutes >= 1440 and $distance_in_minutes <= 2879) {
return '1 day';
} elseif ($distance_in_minutes >= 2880 and $distance_in_minutes <= 43199) {
return 'about ' . round(floatval($distance_in_minutes) / 1440) . ' days';
} elseif ($distance_in_minutes >= 43200 and $distance_in_minutes <= 86399) {
return 'about 1 month';
} elseif ($distance_in_minutes >= 86400 and $distance_in_minutes <= 525599) {
return round(floatval($distance_in_minutes) / 43200) . ' months';
} elseif ($distance_in_minutes >= 525600 and $distance_in_minutes <= 1051199) {
return 'about 1 year';
} else {
return 'over ' . round(floatval($distance_in_minutes) / 525600) . ' years';
}
?>
Additionally, here is the wrapper function:
<?php
/*
* Like distanceOfTimeInWords, but where to_time is fixed to the output of time()
*
*/
function timeAgoInWords($from_time, $include_seconds = false) {
return $this->distanceOfTimeInWords($from_time, time(), $include_seconds);
}
?>
Michael Konecny
17-Jul-2008 09:06
17-Jul-2008 09:06
It should be noted in the example, that time() + (7*24*60*60) and strtotime("+1 week") do not always generate the same timestamp. The problem occurs when the daylight saving time changes.
Therefore it's usually better to use strtotime..
Example:
the last time the time changed in the Czech republic was on the 30th March 2008, from 2:00 to 3:00.
Assume it is Wednesday, the 26th March 2008, 23:59.
If you call
<?php echo date("l, jS F Y, H:i",strtotime("+1 week")); ?>
you get Wednesday, 2nd April 2008, 23:59, as you would predict,
although if you try
<?php echo date("l, jS F Y, H:i",time()+(7*24*60*60)); ?>
you get Thursday, 3rd April 2008, 00:59. Here's where things might get a bit confusing, if you don't expect it!
Suddenly you find the food list for the next week is gone :D !
Santosh Patnaik
31-May-2008 10:06
31-May-2008 10:06
This function formats an elapsed time or a time-difference value by distributing the value in seconds in to years, months, weeks, etc. (akin to using varying numbers of currency notes and coins of different denominations for the same amount of money)
<?php
/*
* Formatted time-difference between $t1 and $t2 (seconds)
* The difference in seconds is distributed into years, months, etc. as specified by $format.
* $format is a string containing characters y, f, w, d, h, m or s, for years, months, weeks, days, hours, minutes or seconds, resp.
* Output is an array containing keys y, f, etc., with the numerical values.
* Values are negative if $t1 is more than $t2.
*/
function FormatTimeDiff($t1, $t2=null, $format='yfwdhms'){
$t2 = $t2 === null ? time() : $t2;
$s = abs($t2 - $t1);
$sign = $t2 > $t1 ? 1 : -1;
$out = array();
$left = $s;
$format = array_unique(str_split(preg_replace('`[^yfwdhms]`', '', strtolower($format))));
$format_count = count($format);
$a = array('y'=>31556926, 'f'=>2629744, 'w'=>604800, 'd'=>86400, 'h'=>3600, 'm'=>60, 's'=>1);
$i = 0;
foreach($a as $k=>$v){
if(in_array($k, $format)){
++$i;
if($i != $format_count){
$out[$k] = $sign * (int)($left / $v);
$left = $left % $v;
}else{
$out[$k] = $sign * ($left / $v);
}
}else{
$out[$k] = 0;
}
}
return $out;
}
print_r(FormatTimeDiff(1, 86402));
print_r(FormatTimeDiff(1, 86402, 'hms')); // distribute into hours, minutes and seconds only
print_r(FormatTimeDiff(1, 86402, 'ds')); // distribute into days and minutes only
print_r(FormatTimeDiff(86402, 1, 'm')); // distribute into only minutes
/*
Output:
Array([y]=>0 [f]=>0 [w]=>0 [d]=>1 [h]=> 0 [m]=>0 [s]=>1)
Array([y]=>0 [f]=>0 [w]=>0 [d]=>0 [h]=>24 [m]=>0 [s]=>1)
Array([y]=>0 [f]=>0 [w]=>0 [d]=>1 [h]=> 0 [m]=>0 [s]=>1)
Array([y]=>0 [f]=>0 [w]=>0 [d]=>0 [h]=> 0 [m]=>-1440.01666667 [s]=>0)
*/
?>
south dot minds at gmail dot com
16-May-2008 08:09
16-May-2008 08:09
Format seconds (if less or equal to 86400) into hours, minutes and seconds ± 1 sec. Change $time and $myLocale to whatever your want and test from CLI (bash - linux) with
t=''; for i in $(seq 1 20); do t=$t"\n"$(php -f seconds2time.php) ; done ; echo -e "$t" | sort -n
<?php
$time = mt_rand(0,86400);
$myLocale = "es_AR";
setlocale(LC_ALL,$myLocale);
$localeconv = localeconv();
$dec_point =$localeconv['decimal_point'];
($time > 86400) ? die("Time must be less than 86400 seconds") : '';
if($time % 3600 == 0){
$t_h[0] = $time/3600;
$t_m[0] = 0;
$t_s[0] = 0;
}else if ($time >= 3600 && ($time % 60) == 0 ){
$t_h = explode($dec_point,$time / 3600);
$t_m = explode($dec_point,('0.'.$t_h[1]) * 3600 / 60);
$t_s[0] = 0;
}else if($time < 3600 && ($time % 60) == 0 ){
$t_h[0] = 0;
$t_m = explode($dec_point,$time/ 60);
$t_s[0] = 0;
}else{
$t_h = explode($dec_point,$time / 3600);
$t_m = explode($dec_point,('0.'.$t_h[1]) * 3600 / 60);
$t_s[0] = ceil(('0.'.$t_m[1]) * 60);
}
print sprintf('%05d',$time) .' = ' . sprintf('%02d',$t_h[0]). ' hs. '. sprintf('%02d',$t_m[0]) . ' min. ' .sprintf('%02d',$t_s[0]) ." seg. \n";
?>
binupillai2003 at yahoo dot com
02-Apr-2008 10:10
02-Apr-2008 10:10
Calculate time difference(24 hours system)
<?php
//Author Binu.v.Pillai
function diffTime($bigTime,$smallTime)
{
//input format hh:mm:ss
list($h1,$m1,$s1)=split(":",$bigTime);
list($h2,$m2,$s2)=split(":",$smallTime);
$second1=$s1+($h1*3600)+($m1*60);//converting it into seconds
$second2=$s2+($h2*3600)+($m2*60);
if ($second1==$second2)
{
$resultTime="00:00:00";
return $resultTime;
exit();
}
if ($second1<$second2) //
{
$second1=$second1+(24*60*60);//adding 24 hours to it.
}
$second3=$second1-$second2;
//print $second3;
if ($second3==0)
{
$h3=0;
}
else
{
$h3=floor($second3/3600);//find total hours
}
$remSecond=$second3-($h3*3600);//get remaining seconds
if ($remSecond==0)
{
$m3=0;
}
else
{
$m3=floor($remSecond/60);// for finding remaining minutes
}
$s3=$remSecond-(60*$m3);
if($h3==0)//formating result.
{
$h3="00";
}
if($m3==0)
{
$m3="00";
}
if($s3==0)
{
$s3="00";
}
$resultTime="$h3:$m3:$s3";
return $resultTime;
}
?>
rana_0036 at yahoo dot com
16-Mar-2008 11:03
16-Mar-2008 11:03
Here some example i have implemented. I think it will be helpful someone.
<?php
function fullDateFormat( $value ){
$d = explode("-", $value);
$cdate = date ("F j, Y", mktime (0,0,0,$d[1],$d[2],$d[0]));
echo $cdate;
}
//-----Enter date format like mysql date (e.g. 2000-01-30)------//
fullDateFormat("2008-03-17");
function detailsDateFormat( $value ){
$d = explode("-", $value);
$cdate = date ("l F j, Y", mktime (0,0,0,$d[1],$d[2],$d[0]));
echo $cdate;
}
//-----Enter date format like mysql date (e.g. 2000-01-30)------//
detailsDateFormat("2008-03-17");
?>
miguelangeldavila at yahoo dot com dot mx
24-Dec-2007 09:50
24-Dec-2007 09:50
PHP is affected by the Y2K38 bug.
<?php
$current_time = time();
$years_from_now = 50;
$remaining_seconds = 60 * 60 * 24 * 365 * $years_from_now;
$future_unix_time = $current_time + $remaining_seconds;
$future_date = date('Y-m-d', $future_unix_time);
echo $future_date;
// 1921-11-05
?>
It is caused because the PHP uses the C 32 bits time function
stack-phpnotes at landstander dot com
22-Oct-2007 04:31
22-Oct-2007 04:31
My modification and enhancements to the timeDiff() function last updated by sean sullivan. The rewrite was done to add a couple new optional parameters but I also got a bump in performance. On a completely personal preference level I changed the month and year second values with ones I got from Google searches.
Written and tested with 5.2.0.
Options include
to = time(); date to compute the range to
parts = 1; number of parts to display max
precision = 'second'; lowest part to compute to
distance = TRUE; include the 'ago' or 'away' bit
separator = ', '; separates the parts
<?php
function timeDiff($time, $opt = array()) {
// The default values
$defOptions = array(
'to' => 0,
'parts' => 1,
'precision' => 'second',
'distance' => TRUE,
'separator' => ', '
);
$opt = array_merge($defOptions, $opt);
// Default to current time if no to point is given
(!$opt['to']) && ($opt['to'] = time());
// Init an empty string
$str = '';
// To or From computation
$diff = ($opt['to'] > $time) ? $opt['to']-$time : $time-$opt['to'];
// An array of label => periods of seconds;
$periods = array(
'decade' => 315569260,
'year' => 31556926,
'month' => 2629744,
'week' => 604800,
'day' => 86400,
'hour' => 3600,
'minute' => 60,
'second' => 1
);
// Round to precision
if ($opt['precision'] != 'second')
$diff = round(($diff/$periods[$opt['precision']])) * $periods[$opt['precision']];
// Report the value is 'less than 1 ' precision period away
(0 == $diff) && ($str = 'less than 1 '.$opt['precision']);
// Loop over each period
foreach ($periods as $label => $value) {
// Stitch together the time difference string
(($x=floor($diff/$value))&&$opt['parts']--) && $str.=($str?$opt['separator']:'').($x.' '.$label.($x>1?'s':''));
// Stop processing if no more parts are going to be reported.
if ($opt['parts'] == 0 || $label == $opt['precision']) break;
// Get ready for the next pass
$diff -= $x*$value;
}
$opt['distance'] && $str.=($str&&$opt['to']>$time)?' ago':' away';
return $str;
}
?>
Usage:
$span = timeDiff($when);
or
$span = timeDiff($when, array('parts' => 3));
Josh Abraham
28-Sep-2007 07:43
28-Sep-2007 07:43
When dealing with the results of the time function, taking the modulus (remainder) is often a good way to find recurring information such as day of the week, week of the year, or month of the year. In the example given below of a firefighter's shift, you could do the following to simplify the code.
<?php
function whatShift() {
$referencePoint = mktime(7, 0, 0, 9, 11, 2004); // Sept 11, 2004 at 7AM started an A Shift.
//This is the where we divide the current time since reference by the amount of time in all shifts
//The result of this is the remainder.
$sinceReference = (time() - $referencePoint) % (60 * 60 * 24 * 3);
//The rest of the code can be basically the same so I shortened it here.
if ($sinceReference < 60 * 60 * 25) $shift = "A";
elseif ($sinceReference < 60 * 60 * 49) $shift = "B";
else $shift = "C";
return $shift;
}
?>
jon at freilich dot com
21-Sep-2007 09:30
21-Sep-2007 09:30
Fire Fighters typically work one day on and two days off. Known as shifts and generally referred to as A, B and C. I need to compute this for a web script so I came up with the following function.
Notes: You may need to change the reference date as not all departments are on the same rotation. Also, this does not take into account daylight savings time so the changeover moves by an hour.
<?php
function whatShift() {
$referencePoint = mktime(7, 0, 0, 9, 11, 2004); // Sept 11, 2004 at 7AM started an A Shift.
$now = time();
// Next we need to know how many seconds since the start of the last A Shift.
// First we compute how many 3 days cycles since the reference point then
// subtract that number.
$difference = ($now - $referencePoint);
$cycles = floor($difference / (60 * 60 * 24 * 3));
$sinceReference = ($difference - ($cycles * 60 * 60 * 24 * 3));
if ($sinceReference < 60 * 60 * 25) { // Before the start of the 25th hour it's A Shift.
$shift = "A";
}
elseif ($sinceReference < 60 * 60 * 49) { // Else before the start of the 49th hour it's B Shift.
$shift = "B";
}
else {
$shift = "C"; // Else it's C Shift.
}
return $shift;
}
?>
kobieta dot ryba at gmail dot com
12-Sep-2007 04:23
12-Sep-2007 04:23
Time left function:
<?php
define("TIME_PERIODS_PLURAL_SINGULAR", "weeks:week,years:year,days:day,hours:hour, : ,minutes:minute,seconds:second");
DEFINE("TIME_LEFT_STRING_TPL", " #num# #period#");
/**
* @param $time time stamp
**/
function time_left($time)
{
if (($now = time()) <= $time) return false;
$timeRanges = array('years' => 365*60*60*24,/* 'weeks' => 60*60*24*7, */ 'days' => 60*60*24, 'hours' => 60*60, 'minutes' => 60, 'seconds' => 1);
$secondsLeft = $now-$time;
// prepare ranges
$outRanges = array();
foreach ($timeRanges as $period => $sec)
if ($secondsLeft/$sec >= 1)
{
$outRanges[$period] = floor($secondsLeft/$sec);
$secondsLeft -= ($outRanges[$period] * $sec);
}
// playing with TIME_PERIODS_PLURAL_SINGULAR
$periodsEx = explode(",", TIME_PERIODS_PLURAL_SINGULAR);
$periodsAr = array();
foreach ($periodsEx as $periods)
{
$ex = explode(":", $periods);
$periodsAr[$ex[0]] = array('plural' => $ex[0], 'singular' => $ex[1]);
}
// string out
$outString = "";
$outStringAr = array();
foreach ($outRanges as $period => $num)
{
$per = $periodsAr[$period]['plural'];
if ($num == 1) $per = $periodsAr[$period]['singular'];
$outString .= $outStringAr[$period] = str_replace(array("#num#", "#period#"), array($num, $per), TIME_LEFT_STRING_TPL);
}
return array('timeRanges' => $outRanges, 'leftStringAr' => $outStringAr, 'leftString' => $outString);
}
print_r(time_left(time()-60*60*24*365+59));
?>
Output:
Array
(
[timeRanges] => Array
(
[days] => 364
[hours] => 23
[minutes] => 59
[seconds] => 1
)
[leftStringAr] => Array
(
[days] => 364 days
[hours] => 23 hours
[minutes] => 59 minutes
[seconds] => 1 second
)
[leftString] => 364 days 23 hours 59 minutes 1 second
)
by225 at yahoo dot com
06-Sep-2007 12:32
06-Sep-2007 12:32
A function for converting to Unix time without using the MySQL UNIX_TIMESTAMP function in a query (MySQL allows eight different formats for timestamps):
<?php
function UnixTime($mysql_timestamp){
if (preg_match('/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces)
|| preg_match('/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces)) {
$unix_time = mktime($pieces[4], $pieces[5], $pieces[6], $pieces[2], $pieces[3], $pieces[1]);
} elseif (preg_match('/\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/', $mysql_timestamp)
|| preg_match('/\d{2}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/', $mysql_timestamp)
|| preg_match('/\d{4}\-\d{2}\-\d{2}/', $mysql_timestamp)
|| preg_match('/\d{2}\-\d{2}\-\d{2}/', $mysql_timestamp)) {
$unix_time = strtotime($mysql_timestamp);
} elseif (preg_match('/(\d{4})(\d{2})(\d{2})/', $mysql_timestamp, $pieces)
|| preg_match('/(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces)) {
$unix_time = mktime(0, 0, 0, $pieces[2], $pieces[3], $pieces[1]);
}
return $unix_time;
}
?>
lsd25 at hotmail dot com
01-Sep-2007 07:53
01-Sep-2007 07:53
I did an article on floating point time you can download from my website. Roun movements is the radial ounion movement and there is a quantum ounion movement as well, this code will generate the data for http://www.chronolabs.org.au/bin/roun-time-article.pdf which is an article on floating point time, I have created the calendar system as well for this time. It is compatible with other time and other solar systems with different revolutions of the planets as well as different quantumy stuff.
Thanks:
<?php
if ($gmt>0){
$gmt=-$gmt;
} else {
$gmt=$gmt+$gmt+$gmt;
}
$ptime = strtotime('2008-05-11 10:05 AM')+(60*60*gmt);
$weight = -20.22222222223+(1*gmt);
$roun_xa = ($tme)/(24*60*60);
$roun_ya = $ptime/(24*60*60);
$roun = (($roun_xa -$roun_ya) - $weight)+(microtime/999999);
$nonedeficient = array("seq1" => array(31,30,31,30,30,30,31,30,31,30,31,30),
"seq2" => array(31,30,31,30,31,30,31,30,31,30,31,30),
"seq3" => array(31,30,31,30,30,30,31,30,31,30,31,30),
"seq4" => array(31,30,31,30,30,30,31,30,31,30,31,30));
$deficient = array("seq1" => array(31,30,31,30,30,30,31,30,31,30,31,30),
"seq2" => array(31,30,31,30,31,30,31,30,31,30,31,30),
"seq3" => array(31,30,31,30,31,30,31,30,30,30,31,30),
"seq4" => array(30,30,31,30,31,30,31,30,31,30,31,30));
$monthusage = isset($_GET['deficienty']) ? ${$_GET['deficienty']} : $deficient;
foreach($monthusage as $key => $item){
$i++;
foreach($item as $numdays){
$ttl_num=$ttl_num+$numdays;
}
}
$revolutionsperyear = $ttl_num / $i;
$numyears = round((round(ceil($roun)) / $revolutionsperyear),0);
$jtl = abs(abs($roun) - ceil($revolutionsperyear*($numyears+1)));
while($month==0){
$day=0;
foreach($monthusage as $key => $item){
$t++;
$u=0;
foreach($item as $numdays){
if ($ii<abs($roun)){
$isbelow=true;
}
$ii=$ii+$numdays;
if ($ii>abs($roun)){
$isabove=true;
}
if ($isbelow==true&&$isabove==true){
$daynum = floor(($ii-$numday)-abs($roun));
$month = $u;
$month++;
$isbelow=false;
$isabove=false;
$nodaycount=true;
}
if ($nodaycount==false)
$day++;
$u++;
}
}
}
$timer = substr($roun, strpos($roun,'.')+1,strlen($roun)-strpos($roun,'.')-1);
$roun_out= $numyears.'-'.$month.'-'.$daynum.' '.$day.".$timer";
?>
