Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Output current hour + 1

    I need to output the current hour plus 1 (e.g. if the hour was 1pm it would output 2pm).

    I current have
    PHP Code:
    <?php echo date("H:i:s"); ?>
    which outputs the current time, how would i increment it by an hour?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    PHP Code:
    <?php echo date("H:i:s"mktime(date("H")+1date("i"), date("s"), date("m"), date("d"), date("Y"))); ?>

    Edit,
    If this is a timezone issue, you can use PHP to switch timezones for your server.
    http://php.net/manual/en/function.da...mezone-set.php

    .

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    What it is is im outputting timezoens e.g. GMT 0 GMT +1 GMT +2 etc. Perhaps theres a better way of doing this what i didnt think of?

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Quote Originally Posted by mlseim View Post
    PHP Code:
    <?php echo date("H:i:s"mktime(date("H")+1date("i"), date("s"), date("m"), date("d"), date("Y"))); ?>

    Edit,
    If this is a timezone issue, you can use PHP to switch timezones for your server.
    http://php.net/manual/en/function.da...mezone-set.php

    .
    Or perhaps:

    PHP Code:
    <?php
    echo date("H:i:s",mktime()+3600); //3600 seconds = 1 hour.
    ?>

  • #5
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Another solution:
    PHP Code:
    date'H:i:s'strtotime'+1 hour' ) ) 

  • #6
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Thanks, all those work fine

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    With date_default_timezone_set you specify a city within the timezone.
    There is a specific list of cities to choose from. Once you set that, all
    date functions after that (in the same script) will be using your timezone
    for all calculations.

    So, if you ask the user to pick a city from a list, you could set it that way too.

    I live near St. Paul, Minnesota ...
    So I would pick this timezone for me ...

    <?php
    date_default_timezone_set('America/Chicago');

    The main reason I do that is, my webhost server is on the East Coast,
    so their time is one hour ahead of me. I always force them to use my timezone
    if I'm concerned about specific hours within dates.


    .

  • #8
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Ive set the timezone to my localtime, however im outputting a GMT timelist eg GMT +0 = hh:mm, GMT +1 = HH:MM etc so i needed to increment the time by one hour


  •  

    Posting Permissions

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