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 6769411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:11:26+00:00 2026-05-26T15:11:26+00:00

My mind seems to be going blank on this one. I have to write

  • 0

My mind seems to be going blank on this one.

I have to write something to figure out which date range todays day/month combination fits into.

I have a set amount of date ranges, which are:

  $dateRanges = array(
    1 => "16 January to 30 April",
    2 => "1 May to 30 June",
    3 => "1 July to 15 August",
    4 => "16 August to 15 September",
    5 => "15 September to 15 October",
    6 => "16 October to 15 January"
  );

All I’m trying to return is the array key of the range the current date fits into.

At the moment all thats going through my head is I’ll have to set up a large if statement to look at the current date('j') and date('n') and match the results up. But surely thats pretty messy and not very efficient?

Any ideas of a better way to approach this problem would be much appreciated!

  • 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-05-26T15:11:26+00:00Added an answer on May 26, 2026 at 3:11 pm
    $today = time();
    foreach ($dateRanges as $key => $range) {
       list($start, $end) = explode(' to ', $range);
       $start .= ' ' . date('Y'); // add 2011 to the string
       $end .= ' ' . date('Y');
       if ((strtotime($start) <= $today) && (strtotime($end) >= $today)) {
           break;
       }
    }
    

    $key will be either the index of the matching date range, or null/false.

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

Sidebar

Related Questions

I'm going out of my mind trying to figure out where these 4 <br>
Bearing in mind this is for classic asp Which is better, all HTML contained
This one boggles my mind. I've used this same script (different targets of course)
(I purchased a code signing cert from Thawte and have been going out of
django-mptt seems determined to drive me out of my mind. I'm trying to do
In my mind, both modal dialogs and lightboxes serve the same purpose. It seems
I'm probably going to take some heat for this question. But I'd like to
I am trying to create a digital clock using a Thread as this seems
This probably sounds like a stupid question, but I'm going to give it a
I have a program that is constantly running. Normally, it seems to garbage collect,

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.