Results 1 to 7 of 7
  1. #1

    Default curtime() and a different timezone

    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 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

  2. #2

    Default

    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?

  3. #3
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    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?

  4. #4

    Default

    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

  5. #5
    Join Date
    May 2009
    Posts
    1,576
    Tokens
    0

    Latest Awards:

    Default

    Well done to yourself

  6. #6
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    I decided to clean up the code, it was just for practise and could be wrong:

    PHP Code:
     <?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> '); 
    }
    ?>
    Last edited by Chippiewill; 04-06-2009 at 09:06 PM.
    Chippiewill.


  7. #7

    Default

    Quote Originally Posted by 00chips View Post
    I decided to clean up the code, it was just for practise and could be wrong:
    PHP Code:
    $time curtime() + 60000[b];[/b
    You missed a colon, noticed instantly, can't be bothered to check the rest.

    Oh, and you can't do:
    PHP Code:
    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:
    PHP Code:
    echo( 
    <div class='show'>  
    <p>Current Presenter: 
    $showInfo['presenter'] </p> " ); 

    Last edited by Jam-ez; 05-06-2009 at 03:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •