PDA

View Full Version : curtime() and a different timezone



CurtisKenny
30-05-2009, 09:32 PM
Hey, i've got a php script which uses mysql to get the current on air presenter for a website for a new community radio station website that im working on.

It has been working great until we moved to a server with a US Timezone.

Is there any way to offset the curtime() funtion by +6 hours?

My script code:


<?php
$day = date('D');
$result = mysql_query("SELECT * FROM `$day` WHERE showbegin < curtime() AND showend > curtime()");

if(!$result){
echo "There has been an error in retrieving the current presenter. ";
} else {
$showInfo = mysql_fetch_assoc($result);
?>


<div class="show">
<p>Current Presenter: <?php echo $showInfo['presenter'] ?></p>
<?php } ?>

The script is liked up to a database with 7 tables (Mon, Tue, Wed, Thu, etc) and checks for the time from the showbegin and showend columns (data type set at time)

Thanks in advance
Curtis

CurtisKenny
03-06-2009, 04:36 PM
I hate to bump my own thread (and im sorry if i broke the rules) but i think you cannot edit the curtime() timezone.

Can someone else suggest another way of pulling this sort of query from the database?

I thought about converting the current time into a decimal (as you can edit the timezone using php) and comparing it to the database. I tried this but got an error.

what do you think?

Blinger1
04-06-2009, 01:16 AM
Couldn't you just do something like "$time = $curTime + 6" ? or some crap?

What i mean is, get the current time and just add 6 hours onto it?

CurtisKenny
04-06-2009, 09:31 AM
i figured out how to do it!

I used: CURTIME() + 60000 which adds 6 hours

and for reference:

curtime()+100 adds 1 minute
curtime()+1000 adds 10 mins
curtime()+10000 adds an hour

lick
04-06-2009, 12:54 PM
Well done to yourself :P

Chippiewill
04-06-2009, 09:03 PM
I decided to clean up the code, it was just for practise and could be wrong:



<?php
$day = date('D');
$time = curtime() + 60000
$result = mysql_query("SELECT * FROM `$day` WHERE showbegin < $time AND showend > $time");

if(!$result){
echo "There has been an error in retrieving the current presenter. ";
} else {
$showInfo = mysql_fetch_assoc($result);
echo('
<div class=\"show\">
<p>Current Presenter: $showInfo['presenter'] </p> ');
}
?>

Jam-ez
05-06-2009, 03:50 PM
I decided to clean up the code, it was just for practise and could be wrong:



$time = curtime() + 60000;
You missed a colon, noticed instantly, can't be bothered to check the rest. :)

Oh, and you can't do:


echo('
<div class=\"show\">
<p>Current Presenter: $showInfo['presenter'] </p> ');
}

Because it'd cut off the echo and then reopen it again.. which would fail. You'd have to do:


echo( "
<div class='show'>
<p>Current Presenter: $showInfo['presenter'] </p> " );
}

Want to hide these adverts? Register an account for free!