Re: PHP Another time "a"round
| From: | CPT John W. Holmes | Date: | Fri, 04 Apr 2003 19:38:10 +0000 |
| Subject: | Re: PHP Another time "a"round | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-142411@lists.php.net to get a copy of this message | ||
> I'm getting close to what I want...I currently have this code which loops
> through all of the next 24 hours:
>
> <SELECT NAME="futhour">
> <?
> for($i = 0; $i <= 24; $i++):
> $futhour = strtotime("+$i hour");
> echo '<OPTION VALUE="'. date('H',$futhour)
> .'">'. date('g
> a',$futhour).'</OPTION>';
> endfor;
> ?>
> </SELECT>
>
> is there a way to include the minutes of the hour in the above code, BUT
> have the minutes rounded to the nearest 1/2 hour?
>
> e.g.:
> 12:00
> 12:30
> 1:00
> 1:30
This works. I'm sure there are other ways:
<SELECT NAME="futhour">
<?
$now = time();
$offset = 60-date('i',$now);
for($i = 0; $i <= 1440; $i+=30):
$futhour = mktime(date('H',$now),
date('i',$now)+$i+$offset,
date('s',$now),
date('m',$now),
date('d',$now),
date('Y',$now));
echo '<OPTION VALUE="'. date('H:i',$futhour)
.'">'. date('g:i
a',$futhour).'</OPTION>';
endfor;
?>
</SELECT>
---John Holmes...