tastyniall Posted October 3, 2007 Share Posted October 3, 2007 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 More sharing options...
tastyniall Posted October 4, 2007 Author Share Posted October 4, 2007 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 Link to comment https://forums.phpfreaks.com/topic/71682-help-with-strtotime-function/#findComment-361818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.