Re: [PHP] bumping up hour by one

2002-05-02 Thread Hugh Bothwell


"Tom Beidler" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...

> My mistake. The correct code that works is;
>
> $display_time = date("H:i");
>
> // round time to nearest 15 minute interval
> $display_timex = explode (":",$display_time) ;
> if (($display_timex[1] >= 00) && ($display_timex[1] <= 07)) {
> $insert_time = $display_timex[0] . ":00";
> } elseif (($display_timex[1] >= 8) && ($display_timex[1] <= 22)) {
> $insert_time = $display_timex[0] . ":15";
> } elseif (($display_timex[1] >= 23) && ($display_timex[1] <= 37)) {
> $insert_time = $display_timex[0] . ":30";
> } elseif (($display_timex[1] >= 38) && ($display_timex[1] <= 52)) {
> $insert_time = $display_timex[0] . ":45";
> } elseif (($display_timex[1] >= 53) && ($display_timex[1] <= 59)) {
> $display_timex[0]++;
> $insert_time = $display_timex[0] . ":00";
> }

How 'bout:

// split it in a more readable way
list($hour, $min) = split(" ", date("H i"));

// calculate nearest quarter-hour
$quarters = (int) (($min + 7) / 15);

// check for round-to-next-hour
if (4 == $quarters) {
$quarters = 0;
$hour++;
}

// turn quarter-hours back into minutes
$min = 15 * $quarters;

// format final result
$insert_time = sprintf("%2i:%02i", $hour, $min);



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] bumping up hour by one

2002-05-01 Thread Tom Beidler

operator error. I didn't show all the code. Here it is;

$display_time = date("H:i");

// round time to nearest 15 minute interval
$display_timex = explode (":",$display_time) ;
if (($display_timex[1] >= 00) || ($display_timex[1] <= 07)) {
$insert_time = $display_timex[0] . ":00";
} elseif (($display_timex[1] >= 8) && ($display_timex[1] <= 22)) {
$insert_time = $display_timex[0] . ":15";
} elseif (($display_timex[1] >= 23) && ($display_timex[1] <= 37)) {
$insert_time = $display_timex[0] . ":30";
} elseif (($display_timex[1] >= 38) && ($display_timex[1] <= 52)) {
$insert_time = $display_timex[0] . ":45";
} elseif (($display_timex[1] >= 53) && ($display_timex[1] <= 59)) {
$display_timex[0]++;
$insert_time = $display_timex[0] . ":00";
}

The first if statement has a || instead of an &&

My mistake. The correct code that works is;

$display_time = date("H:i");

// round time to nearest 15 minute interval
$display_timex = explode (":",$display_time) ;
if (($display_timex[1] >= 00) && ($display_timex[1] <= 07)) {
$insert_time = $display_timex[0] . ":00";
} elseif (($display_timex[1] >= 8) && ($display_timex[1] <= 22)) {
$insert_time = $display_timex[0] . ":15";
} elseif (($display_timex[1] >= 23) && ($display_timex[1] <= 37)) {
$insert_time = $display_timex[0] . ":30";
} elseif (($display_timex[1] >= 38) && ($display_timex[1] <= 52)) {
$insert_time = $display_timex[0] . ":45";
} elseif (($display_timex[1] >= 53) && ($display_timex[1] <= 59)) {
$display_timex[0]++;
$insert_time = $display_timex[0] . ":00";
}

Thanks for all that replied.

Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] bumping up hour by one

2002-05-01 Thread John Holmes

Doesn't matter, PHP will juggle the type and make it a number. What do
you get for results, these look like they should work. Are you getting
errors or are you getting odd results?

---John Holmes...

> -Original Message-
> From: Tom Beidler [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 01, 2002 6:06 PM
> To: php list
> Subject: [PHP] bumping up hour by one
> 
> I'm having some problem with some code where I'm trying to round the
hour
> up
> to the next hour if the minutes are between 53 and 59. Here's the
> important
> part of the code so you can see what I'm trying to do.
> 
> $display_time = date("H:i");
> 
> // round time
> $display_timex = explode (":",$display_time) ;
> 
> and then...
> 
>  elseif (($display_timex[1] >= 53) && ($display_timex[1] <= 59)) {
> $display_timex[0]++;
> $insert_time = $display_timex[0] . ":00";
> }
> 
> I've also tried ...
> 
>  elseif (($display_timex[1] >= 53) && ($display_timex[1] <= 59)) {
> $display_timex[0] = $display_timex[0] + 1;
> $insert_time = $display_timex[0] . ":00";
> }
> 
> Is it because display_timex[0] is not a number
> 
> Thanks,
> Tom
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] bumping up hour by one

2002-05-01 Thread Tom Beidler

I'm having some problem with some code where I'm trying to round the hour up
to the next hour if the minutes are between 53 and 59. Here's the important
part of the code so you can see what I'm trying to do.

$display_time = date("H:i");

// round time
$display_timex = explode (":",$display_time) ;

and then...

 elseif (($display_timex[1] >= 53) && ($display_timex[1] <= 59)) {
$display_timex[0]++;
$insert_time = $display_timex[0] . ":00";
}

I've also tried ...

 elseif (($display_timex[1] >= 53) && ($display_timex[1] <= 59)) {
$display_timex[0] = $display_timex[0] + 1;
$insert_time = $display_timex[0] . ":00";
}

Is it because display_timex[0] is not a number

Thanks,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php