Help w/ Offsetting Server Time

Good Morning, All

I read this forum often to find answers to problems but found my first reason to post today. :slight_smile:

I’m working with an application that requires time/date information. The program works so that an “event” is “active” during a certain period of time. (as specified in the admin) The problem is that I just moved this app over to a godaddy server and their local time on the server is 2 hours behind mine. This is causing the app to fail.

I’ve been doing all the research regarding times/dates here: http://php.net/manual/en/function.gmdate.php
However, I’ve been unable to achieve the result without error.

What I need to do is offset the time in my app to 2 hours previous.

[php]function humanize_time($input_time)
{
$returnarray[“date”] = date(“M-d-Y”, $input_time);
$returnarray[“time”] = date(“g:i A”, $input_time);
return $returnarray;
}

function computerize_time($year, $month, $day, $hour, $minute, $second, $ampm)
{
$errorflag=0;
if($month > 12 || $month <1)
{
$errorflag=1;
}
if($year > 2100 || $year < 2000)
{
$errorflag=1;
}
if(!$errorflag)
{
if($month < 10)
{
$month = “0” . $month;
}
$partial_time = strtotime($year . “-” . $month . “-01 20:00:00”);
$days_in_month = date(‘t’,$partial_time);
//echo "Days in Month: " . $days_in_month . “
”;
}
if($day < 1 || $day > $days_in_month)
{
$errorflag=1;
}
if($hour<1 || $hour > 12)
{
$errorflag = 1;
}
if($minute <0 || $minute >59)
{
$errorflag = 1;
}
if($second < 0 || $second >59)
{
$errorflag = 1;
}
if($errorflag == 1)
{
return 0;
}
else
{

	if($day < 10)
	{
		$day = "0" . $day;
	}
	if($ampm == 2)
	{
		if($hour == 12)
		{
			$hour = 12;
		}
		else
		{
			$hour+=12;
		}
	}
	if($ampm == 1)
	{
		if($hour == 12)
		{
			$hour = 0;
		}
	}
	if($hour < 10)
	{
		$hour = "0" . $hour;
	}
	if($minute < 10)
	{
		$minute = "0" . $minute;
	}
	if($second < 10)
	{
		$second = "0" . $second;
	}
	$timestring = $year . "-" . $month . "-" . $day . " " . $hour . ":" . $minute . ":" . $second;
	return strtotime($timestring);
}

}[/php]

If someone would be so kind as to help me understand where to set this, I would be greatly appreciative.

Thanks in advance for any help you can provide!

Cheers!

Well I got the first function figured out:
[php]
function humanize_time($input)
{
$offset = 60602;
$input_time=$input-$offset;
$returnarray[“date”] = date(“M-d-Y”, $input_time);
$returnarray[“time”] = date(“g:i A”, $input_time);

return $returnarray;
}
[/php]
I am trying to figure out the second one :smiley:

oh I was making too big of a deal out of it, when it was as simple as:
[php]
function computerize_time($year, $month, $day, $hour, $minute, $second, $ampm)
{
$errorflag=0;
if($month > 12 || $month <1)
{
$errorflag=1;
}
if($year > 2100 || $year < 2000)
{
$errorflag=1;
}
if(!$errorflag)
{
if($month < 10)
{
$month = “0” . $month;
}
$partial_time = strtotime($year . “-” . $month . “-01 20:00:00”);

$days_in_month = date(‘t’,$partial_time);

//echo "Days in Month: " . $days_in_month . “
”;
}
if($day < 1 || $day > $days_in_month)
{
$errorflag=1;
}
if($hour<1 || $hour > 12)
{
$errorflag = 1;
}
if($minute <0 || $minute >59)
{

$errorflag = 1;
}
if($second < 0 || $second >59)
{

$errorflag = 1;
}
if($errorflag == 1)
{

return 0;
}
else
{

if($day < 10)

{

$day = “0” . $day;

}
if($ampm == 2)

{

if($hour == 12)

{

$hour = 12;

}
	
else
	
{

$hour+=12;

}

}
if($ampm == 1)

{

if($hour == 12)

{

$hour = 0;

}

}
if($hour < 10)

{

$hour = “0” . $hour;

}
if($minute < 10)

{

$minute = “0” . $minute;

}
if($second < 10)

{

$second = “0” . $second;

}
$timestring = $year . “-” . $month . “-” . $day . " " . $hour . “:” . $minute . “:” . $second;
$offset = 60602;

$final=strtotime($timestring)-$offset;
return $final;
}
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service