dadamssg Posted March 30, 2009 Share Posted March 30, 2009 im trying to use mktime or gmmktime to calculate dates based on a date selection, month, day, year, hour, min, am/pm..and im trying to set it up where if pm is selected it will add 12 to the hours. it works fine from 1am-11pm...but when i input 12 pm it will calculate it as one hours short(11pm) but i tried to make some if stmts where if ampm equals 12 it will only add 11 hours but when i change that...it ouputs the next day 12am...really confused.... heres the code that outputs 11pm when 12pm is selected if($_POST['eampm'] == "pm" && $_POST['ehour'] == "12") { $ehour = $_POST['ehour'] + 11; $_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$ehour.":".$_POST['eminute'].":00"; $end = mktime($ehour, $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); } elseif($_POST['eampm'] == "pm" && $_POST['ehour'] !== "12") { $ehour = $_POST['ehour'] + 12; $_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$ehour.":".$_POST['eminute'].":00"; $end = mktime($ehour, $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); } else{ $end = mktime($_POST['hour'], $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); $_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$_POST['hour'].":".$_POST['eminute'].":00"; } and heres the code that outputs march 31 12am if i input today, march 30 12pm if($_POST['eampm'] == "pm" && $_POST['ehour'] == "12") { $ehour = $_POST['ehour'] + 12; $_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$ehour.":".$_POST['eminute'].":00"; $end = mktime($ehour, $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); } elseif($_POST['eampm'] == "pm" && $_POST['ehour'] !== "12") { $ehour = $_POST['ehour'] + 12; $_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$ehour.":".$_POST['eminute'].":00"; $end = mktime($ehour, $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); } else{ $end = mktime($_POST['hour'], $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); $_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$_POST['hour'].":".$_POST['eminute'].":00"; } Link to comment https://forums.phpfreaks.com/topic/151788-help-with-adding-pm-to-a-time-selection/ Share on other sites More sharing options...
dadamssg Posted March 30, 2009 Author Share Posted March 30, 2009 just kidding..the pm selection list works except for 12 pm, but when 6:15 am is selected it outputs 12:15am Link to comment https://forums.phpfreaks.com/topic/151788-help-with-adding-pm-to-a-time-selection/#findComment-797024 Share on other sites More sharing options...
dadamssg Posted March 30, 2009 Author Share Posted March 30, 2009 noone? Link to comment https://forums.phpfreaks.com/topic/151788-help-with-adding-pm-to-a-time-selection/#findComment-797076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.