Php time minus 5 minutes

Asked 10 years, 1 month ago

Viewed 28k times

I would like to show me the date minus 5 minutes from the current time; my code is like this:

(date('Y-m-d H:i-5:s'))

but it's not correct because var_dump produces:

2012-08-08 13:27-5:49

Any ideas on how can I do this?

Php time minus 5 minutes

Marcello B.

3,90211 gold badges46 silver badges62 bronze badges

asked Aug 8, 2012 at 17:31

Php time minus 5 minutes

PHP Function:

strtotime()

Example:

echo date('Y-m-d H:i:s', strtotime('-5 minutes'));

salathe

50.4k11 gold badges103 silver badges130 bronze badges

answered Aug 8, 2012 at 17:33

Jason McCrearyJason McCreary

69.8k21 gold badges128 silver badges170 bronze badges

3

Try this It's solve your problem

$format = "h:i A";
date_default_timezone_set('Asia/Kolkata');
echo date($format, strtotime("-5 minute"));

answered Jan 15, 2018 at 10:54

Php time minus 5 minutes

vivekvivek

3542 silver badges9 bronze badges

November 12, 2021 Category : PHP

This tutorial will give you example of php subtract minutes from datetime. i explained simply about php subtract minutes from current time. We will use how to subtract minutes from time in php. This article goes in detailed on how to subtract minutes from current time in php.

I will give you very simple example how to sub minutes to date and time in PHP. so let's see both example with output:

Example 1: PHP Subtract Minutes to DateTime

index.php

$date = "2021-11-01 10:10:05";

$newDate = date('Y-m-d H:i:s', strtotime($date. ' -10 minutes'));

echo $newDate;

?>

Output:

2021-11-01 10:00:05

Example 2: PHP Subtract Minutes to Current DateTime

index.php

$newDate = date('Y-m-d H:i:s', strtotime(' -10 minutes'));

echo $newDate;

?>

Output:

2021-11-10 06:39:33

i hope it can help you...

Php time minus 5 minutes

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

  • How to Add Seconds to Time in PHP?
  • PHP Add Minutes to Time Example
  • PHP Add Hours to Datetime Example
  • 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?

Popular Posts

  • Laravel 6 CRUD Application Tutorial
  • How to get filename from file path in MySQL?
  • Laravel - Dynamic Dependant Select Box using JQuery Ajax Example - Part 1
  • How to change date format in PHP Codeigniter?
  • How to Convert Array to String in PHP?
  • PHP Codeigniter 3 - Jquery Ajax Autocomplete Search using Typeahead
  • Laravel 5.6 Import Export to Excel and CSV example
  • Laravel Many to Many Polymorphic Relationship Tutorial
  • How to call middleware from controller in Laravel?
  • Laravel age calculate from date using carbon
  • Php jquery ajax post request example

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

  • 13 High-Paying IT Jobs You Can Get Without a Degree
  • How to Get All Routes in Laravel?
  • Laravel Download File from URL to Storage Example
  • How to Remove Numbers from String in PHP?
  • How to Write Text on Existing PDF File in Laravel?

How to minus time from time in PHP?

php $start = strtotime('10-09-2019 12:01:00'); $end = strtotime('12-09-2019 13:16:00'); $hours = intval(($end - $start)/3600); echo $hours. ' hours'; //in hours //If you want it in minutes, you can divide the difference by 60 instead $mins = (int)(($end - $start) / 60); echo $mins.

How do you subtract minutes from a timestamp?

Subtract minutes from a timestamp in Python using timedelta.
Step 1: If the given timestamp is in a string format, then we need to convert it to the datetime object..
Step 2: Create an object of timedelta, to represent an interval of N minutes. ... .
Step 3: Subtract the timedelta object from the datetime object in step 1..

How to trim time from date in PHP?

Subtract time (hours, minutes, and seconds) from date can be easily done using the date() and strtotime() function in PHP. The date() function formats a local date and time, and returns a formatted string.

How can I get different time in PHP?

Use date_diff() Function to Get Time Difference in Minutes in PHP. We will use the built-in function date_diff() to get time difference in minutes. For this, we need a start date and an end date. We will calculate their time difference in minutes using the date_diff() function.