Ty44ler Posted May 5, 2010 Share Posted May 5, 2010 $time = "8:00 AM"; $time2 = $data['arrived'.$i]; //echo's out to be "8:00 AM" if (($timestamp = strtotime($time)) === false) { echo "The string ($time) is bogus"; } else { echo date('h:i A', $timestamp); } This function works when I put in $time but doesn't work when I put in $time2. $time2 echo's out to be "8:00 AM" $data['arrived'.$i] comes from a form that the user selects the time form. Why does $time work, but $time2 doesn't? They echo out the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/ Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 When you say "it doesn't work" what exactly is it not doing? And why exactly are you using === and not == ? Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053637 Share on other sites More sharing options...
Ty44ler Posted May 5, 2010 Author Share Posted May 5, 2010 I'm trying to get a time (8:00 AM) to convert to military time (0800). It doesn't get converted. I noticed my date() function wasn't outputting the right format, but it still didn't work nonetheless. Here's a more basic code of mine: $time2 = '8:00 AM'; echo date('Hi', strtotime($time2))//time2 outputs 0800 $time1 = $_POST['arrived1']; //echo's to be "8:00 AM" echo date('Hi', strtotime($time1)) //time1 outputs 0000 Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053641 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 Can I see your form? as well as the origin of $i. Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053645 Share on other sites More sharing options...
Ty44ler Posted May 5, 2010 Author Share Posted May 5, 2010 Take a look at the second reply. It gives the same results and doesn't use i. $i is just a counter. It'll be actually kind of hard to show you the form, that part of the form is generated dynamically through javascript, but still passes the data the same. Javascript: <form method="post" action="submitworkorder.php" name="ComplianceForm" > <input name=\"arrived'+i+'\" type=\'text\' value=\'8:00 pm\'><input type="submit" value="Preview" name="Preview" /></form> This code is in a for loop that displays it a number of times depending on user input. I cut out most of the stuff that didn't matter. It gets shown through innerHTML javascript. Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053649 Share on other sites More sharing options...
Ty44ler Posted May 5, 2010 Author Share Posted May 5, 2010 I just realized I had date_default_timezone_set('UTC'); set which was messing it up. It still doesn't work as it is giving me 1900 hours now when it should be 0800. Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053657 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 your form lists "value=\'08:00 pm\' " that may be where the 19:00 is coming from. I'm guessing from the escaped single quotes you have this nested in an echo. also, you haven't terminated your first <input> but that's neither here not there for this. Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053679 Share on other sites More sharing options...
Ty44ler Posted May 5, 2010 Author Share Posted May 5, 2010 I had a little revelation... I put in 800 as the value for the formula and it resulted in 1900. This is the same result when I put my variable in there. So, instead of being read as 8:00 AM I believe it is only being read as 800 in the formula (but it clearly echo's out to 8:00 AM). Whyyyyy????? ahhhhh.... :confused: oh and by the way, I edited the values for the input to make sure they weren't messing with anything. Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053696 Share on other sites More sharing options...
Ty44ler Posted May 5, 2010 Author Share Posted May 5, 2010 Alright, after digging around, I've found it has to do with this javascript time selector I had that inputs the data into the text box. Somehow it messes with it so it doesn't believe that it is a string when it's being input. Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053735 Share on other sites More sharing options...
Ty44ler Posted May 5, 2010 Author Share Posted May 5, 2010 figured it out. The javascript string that it was placing in the textbox had a in it. I took it out and placed a regular space in and it worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/#findComment-1053779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.