php dateinterval format. Function Reference. php dateinterval format

 
 Function Referencephp dateinterval format  And here's the extension to the initial \DateInterval class:

See DateInterval::format(). How can you add a DateInterval to a specific DateTime object in PHP? How do you format a DateInterval object to display only the days, hours, and minutes?. this would be really straightforward if it was limited to days or hours - but it needs to support months, which can have variable lengths. 以下のメソッドで使われます。この書式は他とは大きく見た目が異なりますが、非常にシンプルなので理解に困ることは無いでしょう。 DateInterval::__constructThe string representation of the interval must follow a specific format. Program 2: This program uses DateTime::sub () function to subtract the given interval from date object. 5. Adding an interval to a DateTime object. PHP: date_interval_format - Manual. format character Description Example values % Literal % % Y: Years, numeric, at least 2 digits with leading 0: 01, 03: y: Years, numeric: 1, 3: M: Months, numeric, at least 2 digits with leading 0: 01, 03, 12: m. Provide details and share your research! But avoid. Otherwise, days will be FALSE. This is what I need: is the current time/date in the recurring interval. Collectives™ on Stack Overflow – Centralized & trusted content around the technologies you use the most. Constructors Duration::create. It's used to convert a timestamp to a more readable date and time format. DatePeriod::getDateInterval. TL;DR do not use UNIX timestamps. As you have already said yourself , you tried to get duration from Youtube API. Just to expand on previous answers, a function to do this could work like this (changing the time and interval formats however you like them according to this for function. 0, PHP 7, PHP 8) DateInterval::format — Formats the interval Description ¶ public DateInterval::format ( string $format ): string Formats the interval. The newer PHP-Versions provide some new classes called DateTime, DateInterval, DateTimeZone and DatePeriod. Creating. More specifically, the information in an object of the DateInterval class is an instruction to get from one date/time to another date/time. Unlike using strtotime() this will account for daylight savings time and leap year. 2 Answers. Show Hide. Follow edited Sep 2, 2015 at 8:44. Two seconds is PT2S. 3 build (at least on Windows, it always returns the same 6015 value). days. This is mentioned in the documentation for the date function, but bears repeating here. 3. Even with DateInterval though you'll have to do some calculations, since it'll break down an interval into days and hours. You can use '%d' to get the days but it will also return 0 in the case of new \DateInterval('P1Y') as it does not convert years to days. El método DateInterval::format() no recalcula los excesos en cadenas de hora ni en segmentos de fecha. 日付の差. Your output probably doesn't say days = -10 days, but something like days = -10ays. the number of seconds of the number of chosen weeks minus the first week and the current week. If you can't use 5. It seems when creating time-only DateInterval objects, we have to use T too, instead of just P. In this article, we'll discuss how to use PHP's built-in DateTime classes to perform some basic operations on DateTime data. Right now, they are either warnings/errors, or plain “Exception” or “Error”. Find centralized, trusted content and collaborate around the technologies you use most. You can add a comment by following this link or if you reported this bug, you can edit this bug over here. 1 +PHP Version: 7. Trabajando con fechas en PHP y WordPress. If the DateInterval object was created by DateTimeImmutable::diff () or DateTime::diff (), then this is the total number of full days between the start and end dates. e. We can use the class DateInterval to add or subtract some interval in a DateTime object. The DateInterval class is useful for storing a. 3. Return Value: This function returns the DateInterval object of the given date period. DateTime::createFromImmutable — Returns new DateTime instance encapsulating the. When doing difference between DateTimeInterface objects, DateInterval object will be returned. Nobody offered a DateTime object solution yet, so I will. 0. You can't. Calculate the interval between two dates, then format the interval: <?php. DateTime — The DateTime class. If you are not so familiar with the spec of DateInterval like PT12H30M you can proceed with more human readable way using DateInterval::createFromDateString as follows : When putting in the method format the parameters 'i' and 's' in lowercase, when the value to be displayed is less than 10, put a single digit. PHP DateInterval not returning last day of the month. 5. Quoting from PHP. Add a comment. Need to reduce no of days, hours and minutes from a datetime using php. It will return php DateInterval object. The PHP date() function is used to format a timestamp or a date. For procedural style only: A DateInterval object. "); ?>. 8. 3. PHP DateInterval format minutes and seconds with leading zero. This is expected because it is not possible to overflow values like "32 days" which could be interpreted as anything from "1 month and 4 days" to "1 month and 1 day". To achieve what you want going the object oriented style, you have to create a DateTime object first:31 years, 6 months, 14 days Code language: PHP (php) Check out all the DateInterval format parameters. 5. To do so you can simply use DateInterval and loop through it yourself like this: (not start should be ahead of end if you use a negative intervalWe have function which creates a DateTime object from a serialised date string in the session and compares it to now using the DateTime diff function. Notas. 6 and 5. I'm talking about two issues: (1) the number of days in the month which varies from months 1-12 as well as for month 2 which could be leap year (or not); and then issue (2): what if there is the need to specify a large. PHP Collective Join the discussion This question is in a collective: a subcommunity defined by tags with relevant content and experts. It's format is like P29DT48M56. The DateInterval::format method does not recalculate carry over points in time strings nor in date segments. In essence, it does not accord for the day of the month. DateTime::__construct — Returns new DateTime object. We would like to show you a description here but the site won’t allow us. So if you have a date which is May 31, 2016 and want to subtract 3 month intervals, it will: Go back 3 months (in the list of months, don't think days yet), resulting in 'February'. strtotime produces a Unix timestamp as an integer which is helpful if you are for example sorting dates in php. If the DateInterval object was created by DateTime::diff(), then this is the total number of days between the start and end dates. 21. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. If the duration contains time elements, that portion of the specification is preceded by the letter T . how to convert php date format to 3 arguments-1. Where: P is the period designator (required) nY represents the number of years; nM represents the number of months; nD represents the number of days; T is the time designator (required if you're using hours, minutes, or seconds) To format the DateInterval object, we'll need check each value and exclude it if it's 0:. Without PHP 5. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more. days. The DateInterval::format() method does not recalculate carry over points in time strings nor in date segments. I would like to calculate with PHP the start and end datetime of an event. 1. – Example Usage 2. logos-php at kith dot org. But it wont return the number of seconds. Use DateTime (or Carbon). 2. Stack Overflow is leveraging AI to summarize the most relevant questions and answers from the community, with the option to ask follow-up questions in a conversational format. To include those, we simply use the hour, minute and second properties available on the DateInterval object and convert them into seconds as shown in the example above. There are some valid values as examples : 'now' (the default value) 2017-10-19; 2017-10-19 11:59:59; 2017-10. The Overflow BlogTrying to create a list or date interval for the past 2 years, divided into ranges of 6 months, i. The format is as follows: PnYnMnDTnHnMnS. Php Class 'DateInterval' not found. The PHP Date Format function is written as. To format the DateInterval object, we'll need check each value and exclude it if it's 0:PHP has no operator overloading* so + with objects makes PHP trying it to convert them to string first, but DateInterval does not support that:. It takes two parameters: the format and the timestamp. So I wrote my own bulky method but it feels like it should be simpler than this: public TimeSpan FromPhpDateInterval (string phpDateInterval) { // Method to parse php's interval_spec (An interval specification) // The format starts with the letter P, for "period. Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your employer brand I have this string object in my php array "2013-03-05 00:00:00+00" I would like to add 12 hours to the entry within PHP, then save it back to string in the same format. Adding any minutes to a given time is very similar to adding any days to a given date. 1. This function was first introduced in PHP Version 5. I get several dateTime informations through an API. 2. The following examples show some pitfalls of Date/Time arithmetic with regard to DST transitions and months having different numbers of days. Right now, they are either warnings/errors, or plain “Exception” or “Error”. During daylight savings changes 24 hours is not the same as 1 day, which PHP will arrange for you with the proper timezone configuration. DatePeriod::getEndDate — Gets the end date. the number of seconds to reach the end of the first week (which is 7 days minus the day of week of the 1st of January + 1 day) multiplied by the number of seconds per day. The code can be made shorter if you desire. No exception this time. . Esto es así porque no es posible analizar valores como "32 días" el cual podría ser interpretado como cualquier cosa desde "1 mes y 4 días" hasta "1 mes y un día". [2009-06-19 17:19 UTC] pierre dot inglebert at insa-rennes dot fr Description: ----- DateInterval::format method just returns the parameter given. So "m" in the proposed solution will never be bigger than 12. invert. PHP DateTime formatting works but DateInterval formatting not working. DateTime::sub () - Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object. Creates a new DatePeriod object. DateInterval represents a period of time by deconstructing the interval in different parts, years, months, days etc. There is a function format for this. – [2009-06-19 17:19 UTC] pierre dot inglebert at insa-rennes dot fr Description: ----- DateInterval::format method just returns the parameter given. I know I'm a little late but I hope this saves someone a lot time and lines of code. The output when running the above code in PHP 8. Ver también. Adding as new answer instead of rewording / rephrasing old one. 2. Also, if there are no seconds you must omit it from the interval declaration: Also, if there are no seconds you must omit it from the interval declaration:This should be. PHP date_interval_format() Function. B. Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP. When doing difference between DateTimeInterface objects, DateInterval object will be returned. PHP DateInterval Class: The PHP DateInterval class is used to represent an interval between two dates or times. 目次. 3 votes. About; Products. Share. Execute DateInterval::format Online. The minimum amount of instances as retured by the iterator. echo date('Y-m-d', strtotime("+30 days")); strtotime. There's more then one way to do this with DateTime which was introduced in PHP 5. Learn more about CollectivesSo code in if-block returns DateTime while code in else-block returns DateInterval. Nota: . The format starts with the letter P, for "period. Date/Time Arithmetic. Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your employer brand ; Advertising Reach developers & technologists worldwide; Labs The future of collective knowledge sharing; About the companyWhile being the most BC-safe option, this would be completely different to the rest of the PHP date APIs. publicado por Pablo López en Tutoriales el 1 de febrero de 2022. PHP time(): Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). This RFC proposes to introduce Date/Time extension specific exceptions and errors where this makes sense. Twig : DateInterval format minutes with leading zero don't work. I'm trying to get all the Tuesdays and Wednesdays of every two weeks. The DateInterval::format() method does not recalculate carry over points in time strings nor in date segments. You can rate examples to help us improve the quality of examples. Array ( [14] => Array // week ( [1] => 2013-04-01 [2] => 2013-04-02 [3] => 2013-04-03. Thank you for your answers I hope I'm not missing something stupid. El método DateInterval::format() no recalcula los excesos en cadenas de hora ni en segmentos de fecha. 3, I suppose any such conversion function would know how many seconds are in a year, a month, a day, an hour, and a minute. The DateTime class provides options for object and procedural style operations. This is expected because it is not possible to overflow values like "32 days" which could be interpreted as anything from "1. There are three methods that can modify the value of a DateTime instance: add, sub and modify. I would like to calculate with PHP the start and end datetime of an event. php Object of class DateInterval could not be converted to string. Says DateInterval format is wrong. So either the start date is incorrect or the amount of hours you want to add. PHP date_add() function returns a DateTime object with added interval. 0, PHP 7) DateInterval::format— Formats the interval. Improve this answer. PHP | date_create(), date_format(), date_add() Functions; PHP | date_create_from_format() Function; PHP | date_date_set() Function;. Learn more about CollectivesDateTime supports microseconds since 5. The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied. 0, PHP 7, PHP 8) DateInterval::format — Formats the interval Description ¶ public DateInterval::format ( string $format ): string Formats the interval. A duration is the continuous portion of time between two datepoints expressed as a DateInterval object. 31 years, 6 months, 14 days Code language: PHP (php) Check out all the DateInterval format parameters. You can create a DateTime with fractional seconds and retrieve that value using the 'u' format string. 1. It's more readable and also has better support for handling differences between different. For instance, to display the current date,. ini file depending on whether it's running from the CLI or as a CGI from the webserver. The DateInterval::format() method does not recalculate carry over points in time strings nor in date segments. First of all, DateInterval constructor method takes one parameter named $interval_spec which is string. 0 이후 지원되는 은 다른 언어들과 비교하면 아직 모자란 부분이 많이 있지만 그래도 쓸…Get the current date and time. 1. . Table of Contents. If the DateInterval object was created by DateTime::diff(), then this is the total number of days between the start and end dates. date_create(), date_format(), and most [but not all] other date_*() functions are just the procedural interfaces for interacting with DateTime objects. Syntax: Object oriented style:PHP에서의 DateTime은 늘 문자열로 처리되어 를 엄청나게 사용하게 되고, 기간 비교를 위해 timestamp를 직접 다뤄야 하는 번거로움 등 불편함을 다 적기에 시간이 부족할 정도다. DatePeriod::getRecurrences — Gets the number of recurrences. See Also. Esto se debe en gran medida a la cantidad de operaciones que puedes hacer con ellas y la cantidad diferente de. The DateInterval object represents the difference between the two dates. The following code creates a PHP DatePeriod object based off user inputs. until today. 日付文字列で生成. This is done with the usage of DateTime and DateInterval objects and an echo statement to print the relevant years, months, and days. Ask Question Asked 8 years ago. How to create split second DateInterval in PHP? For example: 0. 10 [2019-02-06 08:20 UTC] techouse at gmail dot comBe careful with functions like strtotime() that try to "guess" what you mean (it doesn't guess of course, the rules are here). I used DateInterval::format to display a human readable countdown clock in years, months, and days. Six years and five minutes is P6YT5M. Specifies the format. DateInterval in PHP. 6. 3. " Each duration period is represented by an integer value followed by a period designator. Extract from the PHP dateinterval format documentation below. createFromDateString(30). DateTime is a PHP dateTime object, which provides an OO approach to working with date/time values, plus a lot of sophisticated tools (since PHP 5. 1 Answer. A PHP interval is also used for the storage of a relative time string in a specific format which is supported by the constructor of the DateTime object. The format specifier is the same as supported by date, except when the filtered data is of type DateInterval, when the format must conform to DateInterval::format instead. Stack Overflow. I used a new DateTime in the example to demonstrate the point, but for now assume DateTime is returned from some opaque API that I can't just call over again. Asking for help, clarification, or responding to other answers. To get the current date, you can use the date () function with a format string that specifies the. The class of returned objects is equivalent to the DateTimeImmutable or DateTime ancestor class of the start object. Datetime is of the format Y-m-d H:i:s. 5 chronometer format is supported. The string representation of the interval must follow a specific format. DateTime::add — Modifies a DateTime object, with added amount of days, months, years, hours, minutes and seconds. When I run your code I get the result 2017-10-25 12:22:23. In the Format method, we can convert the DateTime object to a string. The PHP documentation used to have Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (. There's DateInterval though, which handles date intervals. Modified 8 years ago. DateInterval::format (PHP 5 >= 5. e. PHP TWIG date(H:i:s) from seconds. This is expected because it is not possible to overflow values like "32 days" which could be interpreted as anything from "1 month and 4 days" to "1 month and 1 day" . This will give you the date in d/m/Y format while also assuming your initial date was in d/m/Y format. 4. Getting time in seconds. VersionThe value for DateInterval could be changed In 'PT24H'. Why does the 1st DateInterval Object return the value as [d] => 222 and the 2nd DateInterval Object as [days] => 62? What needs to be changed in order for the "222" to appear in the "[days]" tag? phpYou can then use the date Twig filter to format the DateInterval in the view. Calculate business days. class CustomDateInterval extends DateInterval { public function __toString() { // Reading all non-zero date parts. This is expected because it is not possible to overflow values like "32 days" which could be interpreted as anything from "1 month and 4 days" to "1 month and 1 day". . In this example, the difference between two dates is divided into years, months, and days as part of the PHP calculate days between two dates mechanism. 0. Like every time I ask for help, I cannot stop trying and I generally find the answer right after. This RFC proposes to introduce Date/Time extension specific exceptions and errors where this makes sense. 1. There are two ways to convert it. Data/Example: Today : 2013-07-16 12:37 Event Data : Start Date : 2012-04-03 12:30 Interval : 2 Interval Type : week. The procedural version takes the DateTime object as its first argument. In PHP 7 this works (gives e. Call to a member function add() on a non-object when trying to add to DateTime. echo date_create('2011-04-24')->modify('-1 days')->format('Y-m-d'); Running it on Online PHP Editor. 3 is the norm. DateInterval::format(format); Parameter Description; format: Required. DateTime::add () - Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object. Score:. To add an interval to date, you create a new DateInterval object and pass it to the add() method. Main PHP Function Online page. The characters mentioned in the table below can be used in the format parameter string. As Carbon extends DateTime it inherit its methods such as diff() that take a second date object as argument and returns a DateInterval instance. See Also. In order to compare those two dates we use the method diff() of the first. The DateTime class contains add() and sub() methods to manipulate a DateTime instance’s value. Here's what you want with the help of this objects:format: This is a mandatory parameter that specifies the output date string format. DateTime has several. Specify the format. g 03)Catchable fatal error: Object of class DateInterval could not be converted to string in. Introduction. When using the ISO 8601 duration format, T is the time designator that precedes the time components as explained here. Don't want an XFAIL here to cause confusion if a real bug comes up. 2. @ibnɘꟻ I'm aware of it, but the ->format() gives you the ability to globally store the string format in config. (PHP 5 >= 5. And on top of that it's very easy to use. Is there a way of doing this without recursion, perhaps using DateInterval? N. 0 and, works with all the later versions. DateTimeImmutable::add() - Returns a new object, with added amount of days, months, years, hours, minutes and seconds DateTimeImmutable::diff() - Returns the difference between two DateTime objects DateTimeImmutable::modify() - Creates a new object with modified timestamp +add a noteDateInterval::format() with "%F" sometimes shows incorrect value by 1us: Submitted: 2017-04-01 01:35 UTC: Modified: 2020-09-01 12:48 UTC: Votes: 1: Avg. class CustomDateInterval extends \DateInterval { public function __toString() { // Reading all non-zero date parts. Featured on MetaDateTime class Methods in PHP. The above code will output: 1837 days total 5 years 0 months 10 days 6 hours 14 minutes. 3, you should be able to use strtotime the way you did it (I've tested it and it works in both 5. That's what I meant by "the DateInterval contructor". 5 which returns a new DateTime object for every method call instead of updating it (slower). 5. How to format date in PHP from a string of concatenated numbers? 0. DateInterval - Difference between two times. DATE_INTERVAL_ISO8601 ): Most in line with the DateTime API, but probably requires special case handling in format code. Parameters ¶ format Return Values ¶ Returns the formatted interval. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Given its use and long-term availability, depreciation seems. 4. DateTime::createFromFormat () Parses a time string according to a specified format. Comparing PHP DateInterval. I have released it under the MIT license, so feel free to build on top of it or use it in your own project. I have a DateTime, in my case 2021-03-28 08:45. The DateInterval:: format() function is used to format the interval. なぜなら "32 days" のようにオーバーフローした値は "1 month and 4 days" から "1 month and 1 day" までのどれとでも解釈可能だからです。. You can't use date to substract or add days (hours, minutes etc. MySQL datetime: The DATETIME type is used for values that contain both date and time parts. 定義と使用法. The DateInterval::format() method does not recalculate carry over points in time strings nor in date segments. Asking for help, clarification, or responding to other answers. DatePeriod::getRecurrences — Gets the number of recurrences. Method compare makes a value comparison. DateTime::add — Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object. Each date is encapsulated in a DateTime object, and then a difference between the two can be made:. . Introduction. DateTime will return itself or false on failure for every method call. Says DateInterval format is wrong. Take a look at the DateInterval constructor manual page to see how to construct other periods to add to your date (2 days would be 'P2D', 3 would be 'P3D', and so on). PHP Collective Join the discussion. 0, PHP 7, PHP 8) DateTime::sub-- date_sub — Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object Description. Tags. Right now the code assume that both the server and the time in the XML. DateTime::createFromFormat — Parses a time string according to a specified format. Indeed 22-09-2008 will be parsed as 22 September 2008, as it is the only reasonable thing. start_date = 2012-09-06 and end-date = 2012-09-11. Another elegant and reliable method of fetching the previous month’s date is to use PHP’s DateTime(). Following example demonstrates the usage of the date_add() function −If there are more days in the current month, than the month being landed on, the excess overflows to the following month. 注意: . I want to count the total day difference from user input. DateInterval::format() - Formatea el intervalo DateTime::add() - Añade una cantidad de días, meses, años, horas, minutos y segundos a un objeto DateTime DateTime::sub() - Sustrae una cantidad de días, meses, años, horas, minutos y segundos de un objeto DateTime @user5267736, the DateTime format is the same, but when you use diff(), you're returning a DateInterval object, not a DateTime object. Be aware that strtotime can sometimes get the timestamp wrong, if a slightly unconventional format is used. Comparing PHP DateInterval. Below programs illustrate the DateTime::sub () function in PHP: Program 1: This program uses DateTime::sub () function to subtract 2 days from given date object. DateTime::__construct — Returns new DateTime object. 1 second). DateInterval has a special format method for the output. . epoch time), a DateTime object, and a string. Try new DateInterval('P3D') - the days variable is still empty. You also need to call ->format('%d') where you're building the sql statement. The best course of action is using PHP's DateTime (and DateInterval) objects. 0, PHP 7, PHP 8) DateInterval::format — Formats the intervalcheckdate() date_add() date_create_from_format() date_create() date_date_set() date_default_timezone_get() date_default_timezone_set() date_diff(). DateTimeInterface::getTimestamp — Gets the Unix timestamp. The following example adds 1 year 2 months to the date 01/01/2021:It looks like PHP 5. 2 から追加された DateTime クラスの2種類が存在します。. But the. I built on Glavic's answer to add some extra features that I needed;. date format | delete 00´s when year has 00 month or day. The following characters can be used in the format parameter string: % - Literal % Y - Year, at least 2 digits with leading zero (e. 0. The DateInterval::format() method does not recalculate carry over points in time strings nor in date segments. zu erhalten. Example. If you look at the documentation, you will see that class has a days field which you can use to get an integer number of days. 1. The format starts with the letter P, for "period. The formatting characters must be prefixed with a percent sign (%). 2. The Overflow BlogBug #74013: DateTime not able to handle DateInterval on february: Submitted: 2017-01-30 11:23 UTC: Modified: 2017-02-01 09:55 UTC: From: etienne dot chabert at gmail dot comDateInterval::format() does not handle "carry-over points" Submitted: 2010-02-12 20:02 UTC: Modified: 2010-02-17 04:59 UTC: From: m dot kurzyna at crystalpoint dot pl: Assigned: kalle : Status: Closed: Package: Documentation problem: PHP Version: Irrelevant: OS: Linux: Private report: No: CVE-ID: None: View Add Comment Developer. DateTimeImmutable::add — Returns a new object, with added amount of days, months, years, hours, minutes and seconds; DateTimeImmutable::__construct — Returns new DateTimeImmutable object; DateTimeImmutable::createFromFormat — Parses a time string according to a specified format;. 1). The foreach cycle goes at first through years, then months, then days, etc. It also provides the static method, which accepts the input strings and sets up a DateInterval from the. DateInterval::format() - Formatea el intervalo DateTime::add() - Añade una cantidad de días, meses, años, horas, minutos y segundos a un objeto DateTime DateTime::sub() - Sustrae una cantidad de días, meses, años, horas, minutos y segundos de un objeto DateTime +add a note(PHP 5 >= 5. Function Reference. 5. Return time difference as integer. I suspect that your PHP is set to a different timezone than +0800. Persisting Symfony DateIntervalType in doctrine and format it in twig. DateTimeWidgetBase: Creates the basic UI and ensures that the date is using the correct timezone. This function is especially useful when you want to display dates and times in a specific format, or when you need to manipulate date and time values. This effectively makes the interval (14 + 2 + 1 = ) 17 days and 1 hour. How will 08-09-2008 be parsed? Probably 09 August 2008. DateTime::setTime — Legt die Uhrzeit fest. DateTimeInterface::format — Returns date formatted according to given format. Note that use only previous month would result in a behaviour similar to -1 month. Example. This makes the date 2010-02-31. For now I am using this code to find the diffeencePHP DateInterval. DateTime::sub() - Sustrae una cantidad de días, meses, años, horas, minutos y segundos de un objeto DateTime DateTime::diff() - Devuelve la diferencia entre dos objetos DateTime DateTime::modify() - Altera la marca temporal +add a noteDateTimeComputed: Calculate the date value into a format that can be displayed in the widget. I assumed you were starting with user input that you would use to create the DateInterval. However, there is a lot of DateTime functionality that is simply not exposed procedurally, eg: properly modifying the timezone on a DateTime object. See DateInterval::format () .