phpretard Posted December 13, 2010 Share Posted December 13, 2010 I have a form that submits G How can I convert this to string of time when I need to insert it into the database and then turn it back around when it needs to be read? <option>11:00 AM</option> <option>11:30 AM</option> <option>12:00 PM</option> <option>12:30 PM</option> <option>1:00 PM</option> <option>1:30 PM</option> Thank you. Quote Link to comment Share on other sites More sharing options...
phpretard Posted December 13, 2010 Author Share Posted December 13, 2010 Can anyone simplify this function? <? function formattime($it){ $time1 = "$it"; echo strtotime($time1); } formattime("8:30AM"); echo" = "; function readtime($ti){ $time2 = "$ti"; echo date('g:iA', $time2); } readtime('1292247000'); ?> Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 13, 2010 Share Posted December 13, 2010 <?php function halfhourclock($i){ if($i%2==1){ $halfhour=3; }else{ $halfhour=0; } if($i<26){ return floor($i*0.5).':'.$halfhour.'0 AM'; }else{ return floor(($i-24)*0.5).':'.$halfhour.'0 PM'; } } for($i=2;$i<50;$i++){ echo halfhourclock($i).'<br />'; } ?> You can save the time in mysql as a tinyint this way. Probably far better ways of doing it, just thought this would be simple... Quote Link to comment Share on other sites More sharing options...
phpretard Posted December 13, 2010 Author Share Posted December 13, 2010 function converttime($ti){ $format = $ti; $cantread = strtotime($format); echo "$format = $cantread"; }converttime($_POST['PTIME']); exit; Quote Link to comment 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.