Hello friends, How are you all. Friends today we will learn about date in PHP, that how to add or subtract hours in current date and time. Most of developers faces issue in PHP that how to add 1 or custom hours in a current date and we will also know how to add a day in a current date or how to less few day/days from a current date and time. So let’s start this interesting topic.
So our topic will be :
How to add or less hours from a current time in PHP ?
How to add or less days from a current date in PHP ?
First of all we will learn the first above point.
So lets start with a demonstration of code :
How to add or less hours from a current time in PHP ?
In this code , we got time before 1 hour from a current time. if you want to get previous time in any hours later then you need to increase number of hours, suppose i want to get time 2 hours before from the current time then we need to implement this code like this :
Or we you want to change the formation of time then you can also change the format. Suppose i want the hour only from the time hours : minutes : seconds
then the implementation of code will be like this :
$new_time = date(“h A”, strtotime(‘-1 hours’));
So i think guys you learn very well the less and after custom hours in php with the current time. So now we will move on next point that given above.
How to add or less days from a current date in PHP ?
in this topic , we will learn how to get before and days date from a given date in PHP.
After this code we will got the date 10 days before from the current date. Suppose today date is “2022-03-11” then the result will be “2022-03-01”.
So i think you understood this example very well. So guys if you have any suggest about the post and point about this topic then please mention in comment box below. Thanks.