Jump to content

Convert 11 AM to string of time


phpretard

Recommended Posts

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

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');

?>

<?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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.