Viewed   63 times

Having a nightmare at the moment and just can't see why it isn't working

I have a value in the form H:i (ie 10:00, 13:30) etc called $time

What I want to do is create two new values, $startTime which is 30 mins before $time and $endTime which is 30 mins after $time

I have tried the following but just doesn't seem to want to work

$startTime = date("H:i",strtotime('-30 minutes',$time));
$endTime = date("H:i",strtotime('+30 minutes',$time));

If I pass through 10:00 as $time and echo out both $startTime and $endTime I get:

$startTime = 00:30
$startTime = 01:30        


$time = strtotime('10:00');
$startTime = date("H:i", strtotime('-30 minutes', $time));
$endTime = date("H:i", strtotime('+30 minutes', $time));
Monday, December 26, 2022

It might be related to bug #44073

You could try with something like this :

echo date("M", strtotime("-3 month", strtotime(date("F") . "1")) ) . "n";
echo date("M", strtotime("-2 month", strtotime(date("F") . "1")) ) . "n";
echo date("M", strtotime("-1 month", strtotime(date("F") . "1")) ) . "n";
echo date("M", time()) . "n";

(Solution found in the comments section of strtotime ; direct link)

And the output :


Kind of "cheating" with the date format and month's name and all that...

Tuesday, December 13, 2022

AFAIK, you are limited to these two solutions.

You should update to 64-bit system if you can afford it, and if it solves a problem then that's better.

Edit: Just had to check: You could probably try and redefine strtotime() to work with dates prior to 1901.

Tuesday, October 18, 2022

It should be

    $this->result = mysqli_query($this->dbc->dbc, $q);

Note the doubled dbc in the object reference. First one is the private dbc attribute in your Slideshow class, the second dbc is the actual DB handle that's created in your DB class.

Saturday, August 20, 2022

Try this way to add minutes to your time string.

function addMinutesToTime(time, minsAdd) {
  function z(n){ 
     return (n<10? '0':'') + n;
  var bits = time.split(':');
  var mins = bits[0]*60 + +bits[1] + +minsAdd;
  return z(mins%(24*60)/60 | 0) + ':' + z(mins%60);  



Friday, October 7, 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 :