| | |
increment time with for looping
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2006
Posts: 82
Reputation:
Solved Threads: 0
Hi
I am not sure I am approaching this correctly.
I need to increment the appointment time by 15 mins for each loop.
This is would be the correct result:
13:00, 13:15, 13:30, 13:45, 14:00,
This is what I am getting:
13:15, 13:15, 13:15, 13:15, 13:15
The user selects the first appointment example 13:00:00 hrs (HH:MM)
and one or more time blocks. Time blocks range from 1 to 10. Each is 0.15 mins (H).
$event_time = 13:00;//start time
$time_block = 5;// number of loops
$event_length = 0.15;//start time increment by
I am not sure I am approaching this correctly.
I need to increment the appointment time by 15 mins for each loop.
This is would be the correct result:
13:00, 13:15, 13:30, 13:45, 14:00,
This is what I am getting:
13:15, 13:15, 13:15, 13:15, 13:15
The user selects the first appointment example 13:00:00 hrs (HH:MM)
and one or more time blocks. Time blocks range from 1 to 10. Each is 0.15 mins (H).
$event_time = 13:00;//start time
$time_block = 5;// number of loops
$event_length = 0.15;//start time increment by
PHP Syntax (Toggle Plain Text)
<?php /**--------------------------insert appointment in database--------------------------**/ //loop the number of time blocks for($i = 0; $i < $time_block; $i++) { /**---------------------calculate total duration---------------------**/ //Note: event time length * time_block = total event duration //split event time list($event_hour, $event_min) = explode(".",$event_time); //event length list($length_hour, $length_min) = explode(".",$event_length); //convert event time to minutes $event_minutes = ($event_hour * 60) + $event_min; //convert event time length to minutes $length_minutes = (length_hour * 60) + $length_min; //add event time to event duration = next event time $total_min = $event_minutes + $length_minutes++; //convert minutes to hours and minutes if($total_min < 0) { $min =Abs($total_min); } else { $min = $total_min; } $H = Floor($min/60); $M = ($min - ($H * 60))/100; $hours = $H + $M; if($total_min < 0) { $hours = $hours * (-1); } $expl = explode(".",$hours); $H = $expl[0]; if(empty($expl[1])) { $expl[1] = 00; } $M = $expl[1]; if(strlen($M) < 2) { $M = $M . 0; } $new_event_time = $H.".".$M;//total duration /**-------------------database insert statement goes here ------------------**/ } <?
•
•
Join Date: Oct 2006
Posts: 82
Reputation:
Solved Threads: 0
Hi
Thanks for the response.
This is the solution:
[PHP]
$event_time = "13:00";
$time_block = 5;
$event_length = 15; // minutes
for($i = 0, $eTime = strtotime($event_time);
$i < $time_block;
$i++, $eTime = strtotime("+$event_length minutes", $eTime))
{
$new_event_time = date('H:i', $eTime);
echo "<p>$new_event_time</p>\n";
}
[/PHP]
Thanks for the response.
This is the solution:
[PHP]
$event_time = "13:00";
$time_block = 5;
$event_length = 15; // minutes
for($i = 0, $eTime = strtotime($event_time);
$i < $time_block;
$i++, $eTime = strtotime("+$event_length minutes", $eTime))
{
$new_event_time = date('H:i', $eTime);
echo "<p>$new_event_time</p>\n";
}
[/PHP]
![]() |
Similar Threads
- Autonumber in a SQL Server table (MS SQL)
- Project Help: Growth of a Function (Java)
- C++, help!!!!!!! (C++)
- Help with simple problem (C++)
- java client server quiz. interesting!!! (Java)
Other Threads in the PHP Forum
- Previous Thread: is it possible to store a query?
- Next Thread: php is not working
| Thread Tools | Search this Thread |
Tag cloud for PHP
# .htaccess 5.2.10 access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display dissertation download dynamic echo email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link login loop mail menu mlm mod_rewrite multiple mysql mysqlquery oop open parse paypal pdf persist php problem query radio random recursion regex remote script search server sessions sms soap sockets source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube





