This topic is locked
[SOLVED]

 adding minutes to current time

1/18/2012 6:23:06 PM
PHPRunner General questions
S
stiven author

Hello, i have this code on the events page after record added, i need to insert new records on a different table there are about 6 each record goes in an interval of 15 minutes but it isn't working. :/ here is the code



global $conn;
$assign = $values['assign'];

$ctime = time();

$cdate = date('Y-m-d');
$ftaskt = strtotime(date('Y-m-d 16:30:00'));
$tomorrow = time() + 86400;

if($ctime>$ftaskt){
$dbdate = date('Y-m-d',$tomorrow);

}else{

$dbdate = date('Y-m-d');

}
if($assign == '0'){



$strSQLInsert = "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$dbdate."','16:30:00','first_call','".$values['counselor']."','Active')";

db_exec($strSQLInsert,$conn);
}
$extra1 = time() + 7200;//current time was 14:00:00

$timet2 = date('H:m:s',$extra1);//output was 16:00:00
echo "time 2 ".$timet2."<br/>";
if($values['chapel'] == 'Yes' && $assign == '0'){



$strSQLInsert = "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$cdate."','".$timet2."','find_chapel','".$values['counselor']."','Active')";

db_exec($strSQLInsert,$conn);
}
$extra2 = time() + 8100;//current time was 14:00:00

$timet3 = date('H:m:s',$extra2);//output was 16:00:00 i was expecting to be 16:15:00
echo "time 3 ".$timet3."<br/>";
if($values['insurance_funds'] == 'Yes' && $assign == '0'){



$strSQLInsert = "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$cdate."','".$timet3."','insurance','".$values['counselor']."','Active')";

db_exec($strSQLInsert,$conn);
}
$extra3 = time() + 9000;//current time 14:00:00

$timet4 = date('H:m:s',$extra3);//output 16:00:00
if($values['veteran_service'] == 'Yes' && $assign == '0'){



$strSQLInsert = "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$cdate."','".$timet4."','veteran','".$values['counselor']."','Active')";

db_exec($strSQLInsert,$conn);
}
$extra4 = time() + 9900;//current time 14:00:00

$timet5 = date('H:m:s',$extra4);//output was 16:00:00
if($values['inman_service'] == 'Yes' && $assign == '0'){



$strSQLInsert = "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$cdate."','".$timet5."','inman','".$values['counselor']."','Active')";

db_exec($strSQLInsert,$conn);
}

$extra5 = time() + 10800;//current time 14:00:00

$timet6 = date('H:m:s',$extra5);//output was 17:00:00 which was what it was expected
if($values['voc'] == 'Yes' && $assign == '0'){



$strSQLInsert = "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$cdate."','".$timet6."','voc','".$values['counselor']."','Active')";

db_exec($strSQLInsert,$conn);
}
$threehours = time() + 11700;//current time was 14:00:00

$timet7 = date('H:m:s',$threehours);//output 17:00:00 expecting 17:15:00
if($values['viewing_service'] == 'Yes' && $assign == '0'){



$strSQLInsert = "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$cdate."','".$timet7."','viewing','".$values['counselor']."','Active')";

db_exec($strSQLInsert,$conn);
$strSQLUpdate = "UPDATE expedientes SET assign = '1' WHERE case_no = '".$values['case_no']."'";

db_exec($strSQLUpdate,$conn);
}


thanks for your help

Sergey Kornilov admin 1/18/2012

Could you clarify what exactly is not working? Probably you can print SQL queries on the web page instead of executing them to find it time is set properly.

S
stiven author 1/18/2012



Could you clarify what exactly is not working? Probably you can print SQL queries on the web page instead of executing them to find it time is set properly.


all records are inserted on the table the problem is on the time
all the records go to the same table, the table has a time field. for every record inserted i need to make it on a 15 minutes increment. this is what i mean.
when i run the code it was 14:00:00
1st query is two hours after current time so it would be 16:00:00 which is right but then i need to start the increments by 15 minutes but on the database all the records save with the same time 16:00:00
for the first query

$extra1 = time() + 7200;//current time was 14:00:00

$timet2 = date('H:m:s',$extra1);//output was 16:00:00
for the second query

$extra2 = time() + 8100;//current time was 14:00:00

$timet3 = date('H:m:s',$extra2);//output was 16:00:00 i was expecting to be 16:15:00
for 3rd

$extra4 = time() + 9900;//current time 14:00:00

$timet5 = date('H:m:s',$extra4);//output was 16:00:00
4th query

$extra4 = time() + 9900;//current time 14:00:00

$timet5 = date('H:m:s',$extra4);//output was 16:00:00
all the way to here the value saved on the database is 16:00:00
from this point on the value changes to 17:00:00
5th query

$extra5 = time() + 10800;//current time 14:00:00

$timet6 = date('H:m:s',$extra5);//output was 17:00:00 which was what it was expected
$threehours = time() + 11700;//current time was 14:00:00

$timet7 = date('H:m:s',$threehours);//output 17:00:00 expecting 17:15:00

Sergey Kornilov admin 1/19/2012

'm' means 'month'. Instead of 'H:m:s' use 'H:i:s'

S
stiven author 1/19/2012



'm' means 'month'. Instead of 'H:m:s' use 'H:i:s'


omg.. my bad thanks so much!!

Sergey Kornilov admin 1/19/2012

Just for reference here is the link to documentation on PHP's date() function:

http://php.net/manual/en/function.date.php