here is my code for the current date time [now]:
$my_date_time = date['Y-m-d H:i:s'];
how can I add one hour while keeping that format?
asked May 28, 2017 at 4:12
0
$my_date_time = date["Y-m-d H:i:s", strtotime["+1 hours"]]
answered May 28, 2017 at 4:14
Louay HamadaLouay Hamada
7611 gold badge14 silver badges21 bronze badges
You can do this simply with strtotime
function:
$my_date_time = date['Y-m-d H:i:s', strtotime['now +1 hour']];
answered May 28, 2017 at 4:14
Here we are using DateTime
and DateInterval
for getting desired output.
Try this code snippet here
Output:
2021-11-01 13:10:05
Example 2: PHP Add Hours to Current DateTime
index.php
Output:
2021-11-10 06:49:33
i hope it can help you...
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 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 Autocomplete Search from Database using Typeahead JS
- How to Delete Multiple Rows using Checkbox in Codeigniter 3?
- Laravel 5.6 - Login with Facebook with Socialite
- How to integrate stripe payment gateway in Laravel 5.4 Application ?
- PHP Codeigniter get last executed query example
- Codeigniter 3 Datatables Ajax Example From Scratch
- How to install composer using command line in ubuntu ?
- How to Subtract Hours from DateTime in PHP?
- Laravel Deployment on Cloudways with Envoyer
- How to get minimum key value of array in PHP?
- Laravel Vue JS File Upload Using vue-dropzone Example
Categories
- Laravel
- Angular
- PHP
- jQuery
- Bootstrap
- Javascript
- Python
- MySql
- Ajax
- Node JS
- HTML
- Codeigniter
- Ubuntu
- Guest Post
- Vue.JS
- React JS
- Git
- Server
- JSON
- Installation
- CSS
- Google Map
- .htaccess
- SQL
- JQuery UI
- Google API
- Axios
- Socket.io
- Typeahead JS
- Elasticsearch
Latest Posts
- How to Write Text on Existing PDF File in Laravel?
- How to Truncate String in Laravel?
- How to Set Timezone in Laravel?
- Laravel Collection map[] Add Attribute Example
- How to Convert Camel Case to Snake Case in PHP?