chiefrokka Posted February 15, 2008 Share Posted February 15, 2008 I have 3 variables from database that the commish can set as your Deadline to make picks. The commish sees 3 dropdown boxes that say something like "Saturday, 11 pm" $PickDeadline_Day ...........(monday - sunday) $PickDeadline_Hour ..........(1 - 12) $PickDeadline_PM ............(AM or PM) - I need help testing if someone goes to make a pick if the deadline hasn't passed yet or not. - I'd like to display how many days, hours they have left before deadline when they go to the league page thanks in advance Quote Link to comment Share on other sites More sharing options...
craygo Posted February 15, 2008 Share Posted February 15, 2008 Well in order to do something like that you would need a date. Can't use just a day and time. Unless it will always be the day in the current week. Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 15, 2008 Author Share Posted February 15, 2008 yes it will always be the day of the current week. I started playing with date and mktime but wasn't successful. can someone post some example code for me that would work in my case? Quote Link to comment Share on other sites More sharing options...
craygo Posted February 15, 2008 Share Posted February 15, 2008 is there a way you can have them pick a date instead of a day, they can still pick the time but would be much easier to pick a date. The problem comes when you get into the days of the week, you will have problems comparing them when the ends of the week come. Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 15, 2008 Author Share Posted February 15, 2008 i don't want them to pick a specific date because the games are every single weekend and i just want the admin to choose a deadline and have it set every week. if he wants people to only be allowed to make picks up until saturday night every single week that's what i'm trying to do. i really just need to compare the day and time. doesn't matter about the year, month or anything Quote Link to comment Share on other sites More sharing options...
craygo Posted February 15, 2008 Share Posted February 15, 2008 well something simple would be <?php $PickDeadline_Day = "Friday"; // ...........(monday - sunday) $PickDeadline_Hour = "12"; // ..........(1 - 12) $PickDeadline_PM = "PM"; //............(AM or PM) $pick_dead_day = date("U", strtotime("this ".$PickDeadline_Day." ".$PickDeadline_Hour." ".$PickDeadline_PM)); $today_day = date("U"); if($today_day <= $pick_dead_day){ // let them pick echo "I can pick"; } else { echo "I cannot pick"; } ?> Ray Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 15, 2008 Author Share Posted February 15, 2008 ok cool. i'll check it out to see if it works. thanks Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 15, 2008 Author Share Posted February 15, 2008 well something simple would be <?php $PickDeadline_Day = "Friday"; // ...........(monday - sunday) $PickDeadline_Hour = "12"; // ..........(1 - 12) $PickDeadline_PM = "PM"; //............(AM or PM) $pick_dead_day = date("U", strtotime("this ".$PickDeadline_Day." ".$PickDeadline_Hour." ".$PickDeadline_PM)); $today_day = date("U"); if($today_day <= $pick_dead_day){ // let them pick echo "I can pick"; } else { echo "I cannot pick"; } ?> Ray thanks Ray, that seems to be working. great! I'm sort of new to the whole date function so can you explain to me a little how this is working? I'm not sure exactly how this line works. $pick_dead_day = date("U", strtotime("this ".$PickDeadline_Day." ".$PickDeadline_Hour." ".$PickDeadline_PM)); I'm gathering it creates a value in seconds and then compares the seconds for today... but i'm confused on the "this" ? is "this" a keyword date() knows? Quote Link to comment Share on other sites More sharing options...
craygo Posted February 15, 2008 Share Posted February 15, 2008 strtotime uses plain phrases to try and create a date for you. like "april 15th 2007" would be interpreted to the actual date. By using "this" at the begining I am asking for "This friday 12 pm" to try and get the date since today is "this friday" i get todays date. If I used "Last Friday 12 pm" it would give me last fridays date 2/8/2008. So putting in some simple words like "this" and "last" gives you better results. Ray Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 15, 2008 Author Share Posted February 15, 2008 sweet. very powerful function. I'm just now trying to calculate the hours before the deadline now. I'm gathering it's in seconds so I just have to multiple the difference by 3600 to get hours. something like that. thanks again Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 17, 2008 Author Share Posted February 17, 2008 ok, I actually went and made a specific date they can choose for deadline. I can't get my strtotime to work now for some reason. It keeps returning -1 for data My HTML form is now: Month, Day, Year, Hour, PM so they'd input from dropdown boxes: 2 16 2008 11 PM I have $Deadline = date("U", strtotime(" ".$PickDeadline_Month." ".$PickDeadline_Day." ".$PickDeadline_Year." ".$PickDeadline_Hour." ".$PickDeadline_PM." ")); $Today = date("U"); echo "<br>Deadline = ".$Deadline.""; echo "<br>Today = ".$Today.""; but maybe I'm doing something wrong? I keep getting Deadline = -1 Today = 1203262521 Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 17, 2008 Author Share Posted February 17, 2008 bump... can anyone help me solve this last part? i'm gathering it's just a syntax error making it return -1 Quote Link to comment Share on other sites More sharing options...
craygo Posted February 19, 2008 Share Posted February 19, 2008 what do the values look like for the $PickDeadline variables?? try this instead $Deadline = date("U", strtotime($PickDeadline_Month."/".$PickDeadline_Day."/".$PickDeadline_Year." ".$PickDeadline_Hour." ".$PickDeadline_PM)); $Today = date("U"); echo "<br>Deadline = ".$Deadline.""; echo "<br>Today = ".$Today.""; Ray Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 19, 2008 Author Share Posted February 19, 2008 thanks ray. I finally got it solved and ended up using this. <?php $Deadline = strtotime("$PickDeadline_Year-$PickDeadline_Month-$PickDeadline_Day $PickDeadline_Hour $PickDeadline_PM"); $Today = date("U"); ?> then I can compare each value and it seems to be working great. Quote Link to comment Share on other sites More sharing options...
craygo Posted February 19, 2008 Share Posted February 19, 2008 Good to here. Sorry wasn't around to help over the weekend. Do most of my helping here at work. Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted February 19, 2008 Author Share Posted February 19, 2008 thanks ray. I finally got it solved and ended up using this. <?php $Deadline = strtotime("$PickDeadline_Year-$PickDeadline_Month-$PickDeadline_Day $PickDeadline_Hour $PickDeadline_PM"); $Today = date("U"); ?> then I can compare each value and it seems to be working great. ya, I found out you didn't need to put the date() in the Deadline in conjunction with the strtotime because the strtotime converts it for you to value you need to compare. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.