Add minutes to current time php

I am trying to add minutes to current date but it returns strange results

date_default_timezone_set('Asia/Karachi');

$currentDate = date("m-d-Y H:i:s");
$currentDate_timestamp = strtotime($currentDate);
$endDate_months = strtotime("+10 minutes", $currentDate_timestamp);
$packageEndDate = date("m-d-Y H:i:s", $endDate_months);

echo " 
" . $packageEndDate . "
"; echo $currentDate;

I am getting Output

01-01-1970 05:50:00
07-19-2013 20:25:23

It should return

07-19-2013 20:35:23
07-19-2013 20:25:23

After this I need to query to database so date format should be same. Database column is of string type.

asked Jul 19, 2013 at 15:28

Add minutes to current time php

1

Your code is redundant. Why format a timestamp as a string, then convert that string back to a timestamp?

Try

$now = time();
$ten_minutes = $now + (10 * 60);
$startDate = date('m-d-Y H:i:s', $now);
$endDate = date('m-d-Y H:i:s', $ten_minutes);

instead.

answered Jul 19, 2013 at 15:30

Probably the minimalist way would be:

date_default_timezone_set('Asia/Baku');

$packageEndDate = date('Y-m-d H:i:s', strtotime('+10 minute'));
echo $packageEndDate;

Output (Current time in my city at the time of writing):

2017-07-20 12:45:17

answered Jul 20, 2017 at 8:44

Try this:

$now = time();
$tenMinFromNow = date("m-d-Y H:i:s", strtotime('+10 minutes', $time));

answered Jul 19, 2013 at 15:36

SasaTSasaT

7216 silver badges19 bronze badges

$tenMinsFromNow = (new \DateTime())->add(new \DateInterval('PT10M'));

Will leave you with a DateTime object representing a time 10 minutes in the future. Which will allow you to do something like:-

echo $tenMinsFromNow->format('d/m/Y H:i:s');

See it working

PHP version >= 5.4 I'm afraid, but you should be using at least that version by now anyway.

answered Jul 19, 2013 at 18:35

vascowhitevascowhite

17.9k9 gold badges58 silver badges76 bronze badges

Pakistan, which is the localisation explicitly set, uses "DD-MM-YYYY" format dates so the problem occurs when you cast the date into a string of "MM-DD-YYYY". This American format of date is not parseable by the Pakistan localisation.

If you still want to keep the round-trip to a string and back, use DD-MM-YYYY or the ISO datetime format.

While this is the only (current) answer which actually explains your original issue, I recommend the code be refactored as others have demonstrated.

answered Jul 19, 2013 at 15:35

nOw2nOw2

6267 silver badges12 bronze badges

Hi Guys,

In this example,I will learn you add minutes to current date in php.you can easy and simply add minutes to current date in php.

we will show add minutes in current date php.this tutorial will give you example of add minutes to current date using php.

Example:


//Add 5 Minutes in curent date and time

$date = date('d-m-Y H:i', strtotime("+5 min"));

echo ($date);

?>

Output:

21-12-2020 10:48

It will help you...

#PHP

✌️ Like this article? Follow me on Twitter and Facebook. You can also subscribe to RSS Feed.

November 11, 2021 Category : PHP

Here, i will show you how to works how to add minutes to time in php. this example will help you php add minutes to time. you'll learn add 15 minutes to time in php. if you want to see example of how to add 10 minutes to current time in php then you are a right place. Let's get started with add 5 minutes to current time in php.

I will give you very simple example how to add minutes to datetime in PHP. so let's see both example with output:

Example 1: PHP Add Minutes to Time

index.php

$date = "10:10:05";

$newDate = date('H:i:s', strtotime($date. ' +10 minutes'));

echo $newDate;

?>

Output:

10:20:05

Example 2: PHP Add Minutes to Current DateTime

index.php

$newDate = date('H:i:s', strtotime('+10 minutes'));

echo $newDate;

?>

Output:

04:05:51

i hope it can help you...

Add minutes to current time php

Hardik Savani

I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.

Follow Me:

We are Recommending you

  • PHP Subtract Year from Date Example
  • PHP Subtract Month from Date Example
  • How to Subtract Days to Date in PHP?
  • How to Add Year to Date in PHP?
  • How to Add Months to Date in PHP?
  • How to Add Days to Date in PHP?
  • How to get minimum key value of array in PHP?
  • How to find day from specific date in PHP?

Popular Posts

  • Laravel 5.7 Import Export Excel to database Example
  • Laravel 5.7 - Stripe Payment Gateway Integration Example
  • How to create dynamic Highcharts in Codeigniter 3?
  • PHP - How to custom file uploading with CKEDITOR?
  • PHP Subtract Seconds from Time Example
  • PHP Curl Request With Bearer Token Authorization Header Example
  • Example of trigger on after delete with update query mysql
  • Guzzle http client request tutorial with Laravel 5.8
  • How to integrate jQuery Fullcalendar using Bootstrap, PHP and MySQL ?
  • How to Add Text Watermark to Image in PHP?
  • How to Get Tomorrow Date in PHP?

Categories

  • Laravel
  • Angular
  • PHP
  • jQuery
  • Bootstrap
  • Python
  • Javascript
  • MySql
  • Ajax
  • Node JS
  • HTML
  • Codeigniter
  • Ubuntu
  • Guest Post
  • Vue.JS
  • React JS
  • Git
  • Server
  • JSON
  • Installation
  • CSS
  • Google Map
  • SQL
  • .htaccess
  • Google API
  • JQuery UI
  • Axios
  • Typeahead JS
  • Socket.io
  • Highcharts

Latest Posts

  • Laravel Create Record if Not Exists Example
  • How to Set Default Value in Laravel Model?
  • How to Get Last 10 Records in Laravel?
  • How to Get Database Name in Laravel?
  • How to Check Database Connection in Laravel?

How to add 10 minutes to current time in php?

Example 1: PHP Add Minutes to Time.
index.php. $date = "10:10:05"; $newDate = date('H:i:s', strtotime($date. ' +10 minutes')); ... .
Output: 10:20:05..
index.php. $newDate = date('H:i:s', strtotime('+10 minutes')); echo $newDate; ?>.
Output: Read Also: PHP Add Hours to Datetime Example. 04:05:51. i hope it can help you....

How to add minutes in DateTime in php?

For this, you can use the strtotime() method. $anyVariableName= strtotime('anyDateValue + X minute'); You can put the integer value in place of X.

How do you add minutes to current time?

To add minutes in the current date-time, we use AddMinutes() method of DateTime class in C#.

How to add time in time in php?

PHP | DateTime add() Function The DateTime::add() function is an inbuilt function in PHP which is used to add an amount of time (days, months, years, hours, minutes and seconds) to the given DateTime object.