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. Link to comment https://forums.phpfreaks.com/topic/221506-convert-11-am-to-string-of-time/ 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'); ?> Link to comment https://forums.phpfreaks.com/topic/221506-convert-11-am-to-string-of-time/#findComment-1146634 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... Link to comment https://forums.phpfreaks.com/topic/221506-convert-11-am-to-string-of-time/#findComment-1146639 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; Link to comment https://forums.phpfreaks.com/topic/221506-convert-11-am-to-string-of-time/#findComment-1146643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.