Jump to content

deadline comparison


chiefrokka

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.