Jump to content

Something to ponder...


neverett

Recommended Posts

I have a question for everyone to think about.  I've posted some code below.  Here is the situation... You have a server that is hosted in some unknown timezone.  This was the only way I knew possible to always return the current time in the Eastern Timezone (or which ever one you program).  Are there any other ways to do this?  I don't have root access to the server so I think this is the best way.  Let me know if you have any ideas!  I look forward to hearing from you.

 

<?
$sql = "select year(curdate())";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$year = $row['year(curdate())'];
//echo $year;
$march = 14 - (floor(1 + $year * 5 / 4) % 7);
$november = 7 - (floor(1 + $year * 5 / 4) % 7);
//echo $march;
//echo $november;
$dst_starts = mktime(2, 0, 0, 3, $march, $year);
$dst_ends = mktime(2, 0, 0, 11, $november, $year);
//echo $dst_starts;
//echo $dst_ends;
$sql = "select unix_timestamp(utc_timestamp())";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$dt = $row['unix_timestamp(utc_timestamp())'];
//echo $dt;
if( ($dt >= $dst_starts) && ($dt <= $dst_ends) ){
	// DST is in effect (Eastern time zone = UTC -04:00)
	$newtime = $dt - (3600 * 4);
}else{
	// DST is NOT in effect (Eastern time zone = UTC -05:00)
	$newtime = $dt - (3600 * 5);
}
//echo $newtime;
$format = "Y-m-d H:i:s";
$datetime = date($format, $newtime);
echo $datetime;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.