• 0

PHP: Add Minutes To Time


Question

This is bugging me now. I can add, say, 20 minutes to the current time using:

<?
$mytime = ($start = date("H:i:s", strtotime( "$start + 20 mins")));
echo $mytime;
}
?>

But...how would one add 20 minutes to a specified time in text format:

<?
FROM $mytime = "18:00:00";
TO $mynewtime = "18:20:00";
?>

Thanks in advance.

Link to comment
https://www.neowin.net/forum/topic/428545-php-add-minutes-to-time/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

isnt it just something like...

$var = date("H:is:") + 20000;

:unsure:

edit: nvm that doesnt work :p, ill go search about for u.

edit again: couldnt find anything but u might need to do something with 'strtotime' :unsure:

Edited by soil
  • 0

use mktime function in php..i cant remember the order of the params, but it wouldbe something like

$timeshift = mktime(yr,mo,day,hr,min+20,seconds);

$val = date("H:i:s",$timeshift);

codes not exactly right, you would have to stick in the yr, mo, etc...but you can do that by just like date('m') for the month (or whateever the month code is) or

  • 0
  On 03/02/2006 at 23:37, Adrian said:

<?php
echo date("H:i:s", mktime()+(20*60));
?>

and what user really needs (and didn't post) is this:

$date = date("Y-m-d");//or equivalent
$dateParts = explode("-", $date);
$time = date("H:i:s");//or equivalent
$timeParts = explode(":", $time);
$duration = 20;//min

echo date("H:i:s", mktime($timeParts[0], $timeParts[1], $timeParts[2], $dateParts[1], $dateParts[2], $dateParts[0])+($duration*60));

  • 0

This thread follows a trend that bugs me. Every solution proposed so far calculates minutes * seconds. Unless the number of minutes you are adding is variable, there is no reason to have PHP do an extra calculation every time the script runs. If you must remind yourself how you go the value, leave a comment or something.

$increment = 1200; //20 min * 60 sec

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • https://www.neowin.net/news/tags/mastodon/ In short: Federated Twitter (X)
    • Keep in mind it was purchased by an advertising company. I use SearxNG.
    • I am using Waterfox Private Search now that I started using the Waterfox browser on my PC and Android. Both work great* search waterfox net with full stops in between. * I have an issue where making comments on articles on various websites is difficult with Waterfox on Android as it randomly adds spaces and doubles up on text.
    • I can't believe it was only two years since the last time MS raised their prices and now they think they can do it again so soon. Of course they needed to backtrack on this. I hope Nintendo is next.
    • I guess I gotta be even more specific then since I'm looking for an absolute confirmation.  The mini PC has never booted up or powered on by me. I'm assuming it'll be like buying a new PC from a store. Nothing is set up. Like absolutely nothing on the mini PC because I can't emphasize this enough. My USB drive already has Windows set up on it from my other desktop so I know it's clean. So now I connect it to the mini PC before it's even booted up or go to the desktop. I then turn on the mini PC and boot into the USB drive. I should see an existing partition. I'll delete it and then install Windows again over the entire drive. I don't necessarily want to create a separate partition. Once it installs and boots to the desktop, I'm assuming the drive is "clean" and free of any malware/viruses. Basically, this process will eliminate any potential for malware/viruses to still somehow hide in the SSD and then potentially affect me later.  I'm being very anal about this because I really don't trust anything bought from AliExpress, but the price was very tempting.  Is Windows Defender reliable? Afterwards, if I do a full scan and it doesn't find anything in the SSD and the USB drive, can I be confident the mini PC is now safe and secured to enter my banking credentials? If not, what else can I do to be absolutely certain?
  • Recent Achievements

    • Collaborator
      fernan99 earned a badge
      Collaborator
    • Collaborator
      MikeK13 earned a badge
      Collaborator
    • One Month Later
      Alexander 001 earned a badge
      One Month Later
    • One Month Later
      Antonio Barboza earned a badge
      One Month Later
    • Week One Done
      Antonio Barboza earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      584
    2. 2
      ATLien_0
      219
    3. 3
      Michael Scrip
      170
    4. 4
      Xenon
      136
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!