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
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.