Jump to content

Recommended Posts

afternoon,

 

I'm currently working on a sports team based website, which has the normal stuff you'd expect from such a site (Fixture lists/player profiles/etc). Now I've coded most of it, and it works (mostly, couple of bugs here and there that i haven't dealt with yet), but I'm stuck on one particular part.

 

As you can imagine, having a massive list of fixtures would be quite silly, so i want to be able to set date limits on the SQL query. I've stored in the database a simple string which act as the "cut-off" point between seasons (currently set at 01-August). The idea being that it would find the timestamp for the next August, and for the one that has just passed, then only return games that have a timetamp in this range. The season someone is view can then be changed and so these timestamps would be changed accrodingly.

 

The original code i tried was something like this (it's been rewritten a few times with no success)

$start=strtotime("Next ".$seasonstart);
$end=strtotime("Last ".$seasonstart);

 

All that returns is 0. I did a couple of searches and saw the idea of setting a reference date for strtotime, so i tried:

 

$basedate=strtotime("Now");
$start=strtotime("Next ".$seasonstart,$basedate);
$end=strtotime("Last ".$seasonstart,$basedate);

 

This still returns nothing. I also tried

$start=strtotime("Next August 1");

and this returned nothing as well.

 

 

I am rather stumped at this problem, so if anyone has any suggestions they would be greatly appreciated. :)

Link to comment
https://forums.phpfreaks.com/topic/71682-help-with-strtotime-function/
Share on other sites

hello again,

 

I tried some fresh code, and it does what i need it to do. But is there a more effective way of doing this?!

 

if($season_id>0) //current season or a previous one?
  {
    $base="Now -".$season_id." Years"; //previous season
  }
else
  {
    $base="Now"; //current
  }

$basedate=strtotime($base); //The reference date, either today, or this day in previous years
list($month,$day)=split("[-]",$seasonstart); //get the season start month, $seasonstart has format mm-dd
$curmonth=date("m",$basedate); //get the current month

/*
Most seasons cross over a year (if they don't start on 1st Jan), 
so if we have passed the new year, it will not look at current season,
It will look at next season instead.
*/
if($curmonth<$month) 
  {
    $basedate=strtotime("-1 year",$basedate); //new year, but same season, force year back one
  }

$year=date("Y",$basedate); //get the year of the season start
$curstart=strtotime($year."-".$seasonstart); //season start timestamp
$curend=strtotime("+1 year -1 day",$curstart); //season end timestamp

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.