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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:32:21+00:00 2026-05-26T12:32:21+00:00

I would like to know if there is some easy way to identify seasons:

  • 0

I would like to know if there is some easy way to identify seasons: spring, summer, autumn or winter. I’m have to generate a ‘resume’ and I’d like that if a period of working roughly fits a season (not exactly but with a +/-10 days error for example) it returns spring, summer, autumn or winter.

Like:

  • input: 25/06/2010, 30/09/2010
  • output: Summer 2010

(In Spain summer is between 21 July and 20 September)

  • input: 02/02/2009, 30/04/2010
  • output: 2009-2010

Any idea how to do this?

  • 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-26T12:32:22+00:00Added an answer on May 26, 2026 at 12:32 pm

    As you are looking for a season for a period I quickly wrote this function, it can be improve and may have some bugs but you have somewhere to start.

    function season($period) 
    {
        $seasons    = array(
            'spring'    => array('March 21'     , 'June 20'),
            'summer'    => array('June 21'      , 'September 22'),
            'fall'      => array('September 23' , 'December 20'),
            'winter'    => array('December 21'  , 'March 20')
        );
    
        $seasonsYear = array();
    
        $start      = strtotime($period[0]);
        $end        = strtotime($period[1]);
    
        $seasonsYear[date('Y', $start)] = array();
    
        if (key(current($seasonsYear)) != date('Y', $end))
            $seasonsYear[date('Y', $end)] = array();
    
        foreach ($seasonsYear as $year => &$seasonYear)
            foreach ($seasons as $season => $period)
                $seasonYear[$season] = array(strtotime($period[0].' '.$year), strtotime($period[1].' '.($season != 'winter' ? $year : ($year+1))));
    
        foreach ($seasonsYear as $year => &$seasons) {
            foreach ($seasons as $season => &$period) {
                if ($start >= $period[0] && $end <= $period[1])
                    return ucFirst($season).' '.$year;
    
                if ($start >= $period[0] && $start <= $period[1]) {
                    if (date('Y', $end) != $year) 
                        $seasons = $seasonsYear[date('Y', $end)];   
                        $year = date('Y', $end);
    
                    $nextSeason = key($seasons);
                    $nextPeriod = current($seasons);                
                    do {                    
                        $findNext   = ($end >= $nextPeriod[0] && $end <= $nextPeriod[1]);
    
                        $nextSeason = key($seasons);
                        $nextPeriod = current($seasons);
                    } while ($findNext = False);
    
                    $diffCurr   = $period[1]-$start;
                    $diffNext   = $end-$nextPeriod[0];
    
                    if ($diffCurr > $diffNext)
                        return ucFirst($season).' '.$year;
                    else {
                        return ucFirst($nextSeason).' '.$year;
                    }
                }
            }
        }
    }
    
    echo season(array('07/20/2010', '08/20/2010'));
    echo "\n";
    echo season(array('06/25/2010', '09/30/2010'));
    echo "\n";
    echo season(array('08/25/2010', '11/30/2010'));
    echo "\n";
    echo season(array('12/21/2010', '01/01/2011'));
    echo "\n";
    echo season(array('12/21/2010', '03/25/2011'));
    

    Result:

    /*
    Summer 2010
    Summer 2010
    Fall 2010
    Winter 2010
    Winter 2011
    */
    

    And the except you want for “season year overflow”:

    if (date('Y', $end) != $year) 
        return $year.'-'.date('Y', $end);
    

    Instead of:

    if (date('Y', $end) != $year) 
        $seasons = $seasonsYear[date('Y', $end)];   
        $year = date('Y', $end);
    

    Note: Winter is coming.

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

Sidebar

Related Questions

I would like to know if there is some way to access the values
I'm implementing some code generators, i would like to know if there's any way
I would like to have some space between the same line.. I know there
I would like to know if there is an easy way to strike/cross out
I would like to know if there is some kind of special markup to
I would like to know if there is some kind of instanceof functionality in
hi i would like to know if there is a wayI know some css
I would like to know if there's a way in java to find out
I would like to know if there exists any kind of library or workaround
I would like to know if there is any kind of tool to monitor

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.