richiec Posted August 22, 2008 Share Posted August 22, 2008 Hey guys im having a bit of an issue.. Ill try to explain it best way i can with what it is i am trying to do.. Ok first of all in html i have a select option with a drop down menu with a bunch of names.. Under that i have 2 text boxes for date and time (the user imputs the date and time something happend) Now depending on the drop down select name clicking submit will add a set number of hours to the date and time the user submited. Lets say the user imputs todays date 08-22-08 and the time 12:34pm and lets say they select a name which adds 18 hours onto that time.. if ($_REQUEST["Submit"] != NULL){ $name = $_REQUEST["name"]; $date = $_REQUEST["date"]; $time = $_REQUEST["time"]; if ($name == "some name"){ $add = "18"; // hours to add to the date and time $name = "some name"; } Now the output i would want, would be something like.. "$name will happen again on 08-23-08 at 6:34am" (adding 18 hours to the time and date they imputed) any idea how i would do that could i get an example? Thanks alot, Rich Link to comment https://forums.phpfreaks.com/topic/120888-solved-date-and-mktime/ Share on other sites More sharing options...
.josh Posted August 22, 2008 Share Posted August 22, 2008 maybe something like $ts = strtotime("$date $time") + (60 * 60 * 18); $nt = date("m-d-y g:sa ", $ts); Link to comment https://forums.phpfreaks.com/topic/120888-solved-date-and-mktime/#findComment-623126 Share on other sites More sharing options...
richiec Posted August 22, 2008 Author Share Posted August 22, 2008 Using your idea and the date and time i used in my original post (date 08-22-08 and the time 12:34pm) the output i got was: will happen again on: 10-09-09 6:34 am So the time was right with adding 18 hours however the date was way off, any ideas? Link to comment https://forums.phpfreaks.com/topic/120888-solved-date-and-mktime/#findComment-623140 Share on other sites More sharing options...
.josh Posted August 22, 2008 Share Posted August 22, 2008 Ah I know why. strtotime considers the first number to be the year when using "-" as a separator so it's parsing it as "y-m-d" instead of "m-d-y" You can fix this by changing your form to use "/" instead of "-" like "m/d/y" or by reordering the string using substr or maybe using explode like $date = "08-22-08"; $temp = explode("-",$date); $newdate = $temp[2] . "-" . $temp[0] . "-" . $temp[1]; then strtotime($newdate) etc... Link to comment https://forums.phpfreaks.com/topic/120888-solved-date-and-mktime/#findComment-623144 Share on other sites More sharing options...
richiec Posted August 22, 2008 Author Share Posted August 22, 2008 Awesome, that works perfect now thank you very much. I have never used explode before either and i used that after changing it to / at first i went back to using - and the explode code you gave and it works great.. Thank you again! Rich Link to comment https://forums.phpfreaks.com/topic/120888-solved-date-and-mktime/#findComment-623147 Share on other sites More sharing options...
.josh Posted August 22, 2008 Share Posted August 22, 2008 awesome. one last thing: I accidentally did seconds instead of minutes in the date format it should be $nt = date("m-d-y g:ia ", $ts); Link to comment https://forums.phpfreaks.com/topic/120888-solved-date-and-mktime/#findComment-623159 Share on other sites More sharing options...
richiec Posted August 22, 2008 Author Share Posted August 22, 2008 lol i did actually notice that and corrected it Thanks again bud. Link to comment https://forums.phpfreaks.com/topic/120888-solved-date-and-mktime/#findComment-623204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.