dadamssg Posted March 28, 2009 Share Posted March 28, 2009 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 More sharing options...
dadamssg Posted March 28, 2009 Author Share Posted March 28, 2009 i've figured out that the way im trying to create a timestamp for the end datetime isn't working...anyone know how your suppose to do it? Link to comment https://forums.phpfreaks.com/topic/151551-compare-to-now/#findComment-795973 Share on other sites More sharing options...
dadamssg Posted March 28, 2009 Author Share Posted March 28, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.