Viewed   58 times

In my PHP application I want to calculate the sum of two time variables. I am looking for something like this example.

$time1 = 15:20:00;
$time2 = 00:30:00;
$time = $time1+$time2;



The best way to do this is most likely to use strtotime to convert them to timestamps and then do the adding together:

$o = strtotime($time1)+strtotime($time2);

If I remember right strtotime does support this format.

Otherwise you will need to filter it out yourself.

Monday, August 1, 2022

I would say just build it yourself. You can set it up like this:

$query = "INSERT INTO x (a,b,c) VALUES ";
foreach ($arr as $item) {
  $query .= "('".$item[0]."','".$item[1]."','".$item[2]."'),";
$query = rtrim($query,",");//remove the extra comma
//execute query

Don't forget to escape quotes if it's necessary.

Also, be careful that there's not too much data being sent at once. You may have to execute it in chunks instead of all at once.

Saturday, November 5, 2022

Chrome (and apparently other browsers) was looking for a favicon, or the image that appears next to the page title. As soon as I added a stock image to my page like this:

<!DOCTYPE html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" 

It worked. Thanks to @dev-null-dweller for suggesting this!

Saturday, December 17, 2022

You can use 24:00 or 'tomorrow midnight' to get the next midnight. Your code use 12:00 which is "this noon".

$min = round(date("i") / 15) * 15;
$start = strtotime(date("Y-m-d H:$min:00"));
$end = strtotime('24:00');
$range = array();
while ($start <= $end)
    echo date('h:ia',$start )."</br>";
    $start = strtotime('+15 minutes',$start);

Will outputs:


If you don't want to include "12:00am", you could change <= to <:

while ($start < $end)
Friday, September 23, 2022

The function you're looking for is find_in_set:

 select * from ... where find_in_set($word, pets)

for multi-word queries you'll need to test each word and AND (or OR) the tests:

  where find_in_set($word1, pets) AND find_in_set($word2, pets) etc 
Wednesday, August 17, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :