DateIntervalDateInterval can be used to create a new dateinterval object for our date calculation and uses in any script. In the advance PHP object oriented style for all date & time calculations this format is useful. To specify we have to use some standards which are listed here. The period designations are single character.
The total specification has to start with P and then with an integer value followed by a period designator. All time part has to start with T.
Example : 4 days can be specified as P4D. Here are some more examples of datetime interval specifications
We need to keep the sequence as Year Month and Date , we can't keep at Month Year Date or any other way as we wish.
Same way we can add time also to the sequence , let us try with time only, then we will add both date and time to the sequence
Let us combine date and time both and create an interval object
Adding date interval to date objectWe will try to add the above interval to a new date object. Here is the php script.
The output of above code is here
Be the first to post comment on this article :
More On Date Object
PHP Date & Time class creating and examples of uses
Creating a date interval object and using with php date object
Adding date interval to date object to create new dates
Difference in date by using diff function and using date object
Add or subtract from date object using modify function
Changing parameters of the date object by using setdate function
updating time for a date object to a new value
Gettign the time zone setting of the server
Setting the default time zone of server
Array of time zones available for setting ( total list )
Getting time in seconds elapsed from Epoch time
Local time of the server or different time zones by using localtime() function