Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9236689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:21:25+00:00 2026-06-18T07:21:25+00:00

I have a PHP function that returns bool based on whether the time is

  • 0

I have a PHP function that returns bool based on whether the time is currently in any number of pre-defined “hotzones.” Timezone is America/Chicago (UTC – 0600). The following works:

$d = 60*60;                    /* duration of hotzone */
$o = -(3*24+18)*3600;          /* offset to bring UNIX epoch to 12a Sun local*/
$curTime = (time()-$o)%604800; /* time since 12a Sun */

/* Hotzones */
$hotTime = array();
$hotTime[0 ] = (0*24+11)*3600; /* 11a Sun */
$hotTime[1 ] = (0*24+18)*3600; /*  6p Sun */
$hotTime[2 ] = (2*24+19)*3600; /*  7p Tue */
$hotTime[3 ] = (3*24+ 6)*3600; /*  6a Wed */
$hotTime[4 ] = (3*24+11)*3600; /* 11a Wed */

$hotTimes = count($hotTime);

for ($i = $hotTimes-1; $i>=0; $i--) {
  if (($curTime > $hotTime[$i])&&($curTime < $hotTime[$i]+$d)) {
    return true;
  }
}

return false;

However, I have to manually update for Daylight Savings twice per year, and I have to think there’s a more natural, elegant way to do this than the hackish “offset” I calculated. Has anyone come across a nicer way to do this, that takes into account DST?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:21:26+00:00Added an answer on June 18, 2026 at 7:21 am

    You can use the DateTime class for this:

    $hottimes = array (
        array(
            'start'=> new DateTime('Sun 11:00:00 America/Chicago'),
            'stop'=> new DateTime('Sun 12:00:00 America/Chicago')
        ),
        array(
            'start'=> new DateTime('Sun 18:00:00 America/Chicago'),
            'stop'=> new DateTime('Sun 19:00:00 America/Chicago')
        ),
        array(
            'start'=> new DateTime('Tue 19:00:00 America/Chicago'),
            'stop'=> new DateTime('Tue 20:00:00 America/Chicago')
        ),
        array(
            'start'=> new DateTime('Wed 06:00:00 America/Chicago'),
            'stop'=> new DateTime('Wed 07:00:00 America/Chicago')
        ),
        array(
            'start'=> new DateTime('Wed 11:00:00 America/Chicago'),
            'stop'=> new DateTime('Wed 12:00:00 America/Chicago')
        )
    );
    
    $now = new DateTime();
    
    foreach($hottimes as $hotime) {
        if($now >= $hotime['start'] && $now < $hotime['stop']) {
            return true;
        }
    }
    

    You should not use UNIX timestamps for such things. Using DateTime is the preferred way for that. Also read the comment of Sven. (thanks)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that returns json (networks_function.php builds up some arrays and encodes
PHP: I have made up a function that returns an array. I would like
I have a PHP function that takes a variable number of arguments (using func_num_args()
I have php function, that returns array to JavaScript like this: $data['first'] = 10;
I have a simple PHP function that will grab information from a database based
I have a PHP function that returns an array. What is the best way
this might be a tough question. I have a php function that returns a
I have a php function that fetches and returns tweets data from twitter as
I have a php function that retrieves tweets from Twitter & returns them in
I have a PHP function that returns an array. This is the output of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.