Page 1 of 1

gmdate and time

Posted: Tue Feb 20, 2007 2:58 pm
by SmokyBarnable
What is this code doing?

Code: Select all

$req->StartTimeFrom = gmdate('Y-m-d H:i:s', time() - 60 * 60 * 24 * 15);
$req->StartTimeTo   = gmdate('Y-m-d H:i:s');
It looks like its creating a date range....how could I adjust the date range?

Thanks

Posted: Tue Feb 20, 2007 4:27 pm
by feyd
StartTimeFrom is a date and time in the past. StartTimeTo is the current date and time. Both are shifted to Greenwich time.

Posted: Wed Feb 21, 2007 9:05 am
by SmokyBarnable
I live in the central time zone in the United States. I think it is +6 difference relative to GMT. How would I convert the current GMT to my time zone?

Posted: Wed Feb 21, 2007 9:09 am
by feyd
Use date() or subtract six hours from the time given to the function.

Posted: Wed Feb 21, 2007 9:21 am
by SmokyBarnable
Like this?

Code: Select all

function toGMT($time){
	//set to local time zone relative to GMT (+6 for US CST)
	$step = 6;	
	$mytime = substr($time,11);
	$time_array = explode(":",$mytime);		
	$mydate = substr($time,0,10);
	$date_array = explode("-",$mydate);
	$newtime = date("Y-m-d H:i:s",mktime($time_array[0]-$step,$time_array[1],$time_array[2],$date_array[1],$date_array[2],$date_array[0]));
	return $newtime;
}

Posted: Wed Feb 21, 2007 9:24 am
by feyd
Tested it?

Posted: Wed Feb 21, 2007 9:28 am
by SmokyBarnable
Yes it works...just wanted to see if it was the best way.

Posted: Wed Feb 21, 2007 9:31 am
by feyd
It's a way. I can't say whether it's the best way, nor does it really matter. ;)

Posted: Wed Feb 21, 2007 9:40 am
by Kieran Huggins
8O

Code: Select all

$time-=6*60*60; // if $time is a timestamp

$time = date("Y-m-d H:i:s",strtotime($time.' -6 hours')); // if time begins in the other format