Jump to content

compare to now


dadamssg

Recommended Posts

im storing events...so ive set a date selection list for month, day, year, hour, min, am/pm. i have start and end selection list. i want to check to make sure my input for the end date and time hasn't already ended. events that have already ended are useless in my db

 

this part works

 

$_SESSION['starts'] = $_POST['syear']."-".$_POST['smonth']."-".$_POST['sday']."- ".$_POST['shour'].":".$_POST['sminute'].":00";

$_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$_POST['ehour'].":".$_POST['eminute'].":00";

 

and then i do this to make a timestamp and make the if stmt

 

$end = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$_POST['ehour'].":".$_POST['eminute'].":00";
  
$ends = strtotime($end);

if($ends < time() )
{
$message .= "According to your input, your event has already ended.<br>";
}

 

it sets the error message every time no matter what the input is...help?

Link to comment
https://forums.phpfreaks.com/topic/151551-compare-to-now/
Share on other sites

well now im using mktime() and its working sort of....i don't think what im inputting into mktime() is set to the same timezone as php's time(). cause when i try to input a datetime for an event at say 5:00 pm and the current time where im at is 4:30 it says my event has ended....and it won't work until i put like 10pm, after 10pm it works...no clue whats goin on. heres my revised code

 

//if pm is checked add 12 hours
if($_POST['eampm'] == 'pm')
   {
     $ehour = $_POST['ehour'] + 12;

     $_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$ehour.":".$_POST['eminute'].":00";
      $end = gmmktime($ehour, $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
   }
   else
   {
   $end = gmmktime($_POST['ehour'], $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
   }

$now = time();

if($end <= $now)
{
$message .= "Your event has already ended.<br>";
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/151551-compare-to-now/#findComment-795990
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.